Unwanted Tabs Added After Font Change in Aspose.Words

I encounter an issue where unwanted tab characters are added to the document after applying font changes using Aspose.Words. I am applying font changes (e.g., changing font to Times New Roman) and after the font change, extra tabs appear in the document. This is causing formatting issues
Below is the code I am using to apply font changes and documents
Docx_Tab_Issue.zip (51.0 KB)

. I would appreciate your assistance in resolving this issue.

@nobilex Actually the number of tabs is not changed. There are 5 tabs in both documents. But since fonts have different metrics the text is shifted a bit and the next tab stop is used. You can see this by typing a letter before the tabs in the input document. So there is no issue in Aspose.Words.

@alexey.noskov

I understand that the issue is due to the different metrics of the fonts, which affect the alignment of text relative to the existing tab stops. However, this behavior is creating formatting issues, and I need guidance on how to address it effectively.

The tab stop positions remain unchanged when checked programmatically, but the alignment shifts visually due to differences in font metrics (e.g., Times New Roman vs. Calibri). This causes the appearance of extra spacing or tabs, even though the actual tab stops have not been modified(I attached Images for Reference).

Could you confirm if the visual tab space differences are purely due to font metrics, or is there additional Aspose.Words behavior influencing this?
What is the recommended approach to preserve consistent alignment after changing fonts?
Is there a built-in method in Aspose.Words to dynamically adjust tab stops based on the metrics of the new font?
Would explicitly setting tab stops programmatically resolve this reliably? If so, could you provide sample code or best practices for implementing this

Times New Roman:

calibary

@nobilex

Yes, the visual tab space differences are purely due to font metrics. Aspose.Words does not influence this.

unfortunately, there are no recommendations. This is expected that document layout changes after changing fonts due to difference in font metrics.

No there is no such method as well as there is no such method in MS Word.

I am afraid, there is no easy way to fix this. I can only recommend you to avoid using tabs in your documents to horizontally align the text and use table with fixed cell widths instead.

Thanks, @alexey.noskov. Due to the alignment shift caused by font changes, when I add lining, it starts earlier than expected. If I use the same font as the input document, the alignment and lining are correct (please see the attached screenshots for reference).

It is definitely due to the different font metrics, but I would like to know how to handle this situation effectively. Specifically, when my input document remains the same and I want to apply a different font based on user selection, how can I ensure stable alignment and prevent these shifts? Any guidance or best practices on managing alignment across different fonts would be greatly appreciated!

@nobilex The only possible way to handle this is used the same fonts in the document, on the machine where the document is processed and on the machine where the document is consumed.