Created attachment 140633 [details]
Open the attached samples (ODT for reference, DOC/DOCX as bugdocs), and add border to all sides using Format -> Page...; Borders tab, Set All Four Borders.
The issue will be more apparent if Spacing to Contents is increased to eg. 0.2 cm.
=> Page numbers in TOC fall outside the border (only with DOC/DOCX, not with ODT).
The TOC in DOCX is a bit buggy already, but that's not related.
Observed using LO 220.127.116.11 & 18.104.22.168 / Windows 7.
The number stays in the border in 22.214.171.124, with DOC, DOCX is buggy.
The "regression" was introduced by the commit referenced below. However, I don't think it's directly responsible for the issue, the tab position for TOC should be adjusted when adding a border.
author Miklos Vajna <email@example.com> 2013-01-08 11:57:13 +0100
committer Miklos Vajna <firstname.lastname@example.org> 2013-01-08 14:17:27 +0100
n#793998 sw: add TabOverMargin compat mode
Created attachment 140634 [details]
Sample DOC (saved from ODT)
Created attachment 140635 [details]
Sample DOCX (saved from ODT)
Moving to NEW
The problem is not in DOC/DOCX, or in the compatibility mode mentioned in comment 0.
When an index is (re)generated, every right-aligned tab in its tokens generates a (manually-applied) tabstop position in relevant paragraph, which position is calculated at the right text margin based on the layout. Further layout changes don't update the tabstop, unless user updates the index (right-click->Update index). The first problem (the real bug) is, that calculation of the position does not take borders into account, regardless of compatibility mode.
Still, when the text area is/becomes narrower than the tabstop position (like when right margin increases, or when borders exist), *without* the compatibility mode, the problem is not apparent, since the out-of-textarea tabstop is overriden by the textarea margin, so the number position gets to the expected position dynamically (even no index update necessary). But with the mode active, this becomes immediately visible.
One can check the problem with a new text document: add a heading and a ToC with default settings; then decrease right page margin and see that page number doesn't follow the margin (until index update).
So, to fix this first problem, the patch mentioned above simply considers margins when calculating tabstop position, thus correctly setting it on index creation/update.
The other thing is if we should also update the position dynamically after changing margins/borders (or relayouting that could move the index to another page with different margins/borders). This would be an enhancement, and should be tracked separately; also, we should consider that user can manually change the tabstops (when disabled the index protection; after modifications, the protection could be restored). So, how would we go when the positions were manually tweaked? dynamic update would destroy the overriden values.
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":
tdf#116403: consider borders when updating right-aligned tab in index
It will be available in 6.1.0.
The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
Affected users are encouraged to test the fix and report feedback.