Bug 167183 - Wrong order of ToC Items, if Headlines are used in Header
Summary: Wrong order of ToC Items, if Headlines are used in Header
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
25.2.4.3 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-24 09:20 UTC by p.brandt
Modified: 2025-06-24 12:51 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Minimal example with wrong order of ToC (14.81 KB, application/vnd.oasis.opendocument.text)
2025-06-24 09:22 UTC, p.brandt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description p.brandt 2025-06-24 09:20:51 UTC
Description:
Usage of Headlines inside a header directly followed by a subheader outside of the heading has an impact of the order of entries in the table of contents.

Keywords: FORMATTING, EDITING

Steps to Reproduce:
1.Create 3 Pages
2.First page: Set as "First page" + create "Table of Contents"
3.Second page: Insert a Headline1 in the header 
4.Second page: Insert a Headline2 in the document body
5.Refresh ToC

Actual Results:
The Headline 2 is ordered above Headline 1 in ToC.

Expected Results:
The Headline 1 is above headline 2 in ToC.


Reproducible: Always


User Profile Reset: No

Additional Info:
If an additional empty paragraph is inserted before "Headline2" the order inside ToC is correct.
Comment 1 p.brandt 2025-06-24 09:22:14 UTC
Created attachment 201439 [details]
Minimal example with wrong order of ToC
Comment 2 Mike Kaganski 2025-06-24 09:33:17 UTC
Header is not part of the text flow; it's part of a page style. How can a heading in it be treated at all? What if there are more pages with that style (and that heading)? This is a user error to put it there.
Comment 3 p.brandt 2025-06-24 09:47:50 UTC
I stumbled accross this behaviour while converting an older Word File to a Writer-template.

In my Word-File there are chapter/section headlines inside the header, which must not appear in the text flow.

I converted them to headlines in LOW to make an auto generated index possible.
In my real life example I have multiple pages with the same chapter/section heading, and it is treated quite good in the ToC, meaning: The headline inside the heading only appears once in the ToC and mostly in the correct order. (First occurence = Page association)

Only if the a subheadline starts directly at the beginning of the page I got an issue with the order inside ToC.

If there is a better way to achieve my goal, I am open to suggestions.
Comment 4 Mike Kaganski 2025-06-24 09:51:42 UTC
(In reply to p.brandt from comment #3)
> If there is a better way to achieve my goal, I am open to suggestions.

The proper way is to put headings in the text flow. It is not clear what you mean by "which must not appear in the text flow", so that makes it impossible to understand your goal, and hence to suggest how to achieve it better.
Comment 5 p.brandt 2025-06-24 11:52:16 UTC
I describe the use case:

We have a document, which has multiple chapters. Each chapter can span multiple pages.
On every page at the very top the name of the current chapter has to appear.
Each chapter may contain multiple sections and subsections.

The chapternames as well as the headlines of the (sub-)sections have to appear in the ToC.

E.g.

Chapter 1
1.1 Section 1
1.2 Section 2
Chapter 2
2.1 Section 3
2.2 Section 4
2.2.1 Section 4.1
...

Because the name of the chapter has to appear on every page I would use the "header" with "headline", and use this as a base for an auto-generated ToC.
Comment 6 Mike Kaganski 2025-06-24 11:59:19 UTC
(In reply to p.brandt from comment #5)

For your use case, a dedicated feature exists: you put your level 1 heading in the main flow, where it belongs, right before the level 2 heading; and in your header, you place a Document field of type "Heading", format "Heading contents", and level 1. This field changes dynamically, when you go from one chapter to another, and allows to use the same page style for all chapters.

You still didn't address what does "must not appear in the text flow" mean.
Comment 7 p.brandt 2025-06-24 12:32:41 UTC
(In reply to Mike Kaganski from comment #6)

Thank you for your constructive and fast reply.

> For your use case, a dedicated feature exists: you put your level 1 heading
> in the main flow, where it belongs, right before the level 2 heading; and in
> your header, you place a Document field of type "Heading", format "Heading
> contents", and level 1. [...]

If I did that, I would have the name of the chapter twice on the first page of each chapter and therefore redundant. This is not desirable due to visual/design aspects. This is what i mean with "must not appear in the text flow".
Comment 8 Mike Kaganski 2025-06-24 12:51:48 UTC
(In reply to p.brandt from comment #7)
> If I did that, I would have the name of the chapter twice on the first page
> of each chapter and therefore redundant. This is not desirable due to
> visual/design aspects. This is what i mean with "must not appear in the text
> flow".

This is usually mitigated by having a dedicated page style specifically for the first page of chapter. This is implemented by creating such a separate page style; configuring it as you want (e.g., disabling its header, or making it not include the discussed field); in the style's General properties, setting up the "Next style" to be the style with the discussed field in the header; and finally, in the Heading 1 paragraph style, assigning the created "first page of chapter" to the "page break before" on the paragraph style's Text flow tab.

This all turned into a "how to use this software", which is off-topic here, and should be discussed on e.g. http://ask.libreoffice.org, hopefully after reading guides and documentation available at https://documentation.libreoffice.org/en/english-documentation/.

For this issue, it is important to decide, how to proceed with the difference in handling of the incorrect document structure, which you demonstrate here, which may affect interoperability with Word (which lacks advanced features of page management, and provoke its users to do what you show).

Likely it should be confirmed. I am still unsure.