Content heading not shown in table of contents

i have set the “contents heading” style to be level 1 from outline and list. but when i update the table of content that heading is not shown in the table of content? and if i insert a second table of content the heading is shown.
how to do so as just 1 table of content show its own heading?

Version: 24.2.2.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 4; OS: Linux 6.9; UI render: default; VCL: kf6 (cairo+wayland)
Locale: ar-DZ (en_US.UTF-8); UI: en-US
24.2.2-2
Calc: threaded
manjaro os
save format: odt

file that explain the problem:
LO table of content problem.odt (11.2 KB)

Edit your question to mention OS name, LO version and save format. Do this by clicking on below the question, then on the “pencil” icon.

Best diagnostic can be done with a sample file. Please attach your document (max 3 pages). If it contains private data, replace it with dummy text.

1 Like

thank you. i did what you say.

LO table of content problem_2.odt (38,1 KB)

so if i remove the title from the table of content it shows in the index.
but if i want to show them both?

That will not work.

The difference between your occurrences of TOC can be explained as follows.

When a TOC is built or updated, Writer internally first deletes the existing TOC, then scans the document to collect the paragraphs with a non-null outline level.

Therefore your first TOC will not include its own heading (Contents Heading set at level 1) because it does not exist until the TOC is created and displayed but will include “TOC2” heading. Similarly the second TOC will not show its own heading but the one of the the first.

This become obvious if you Tools>Update>Update All.

You may objet that your first TOC in your document doesn’t show “TOC2”. This is only a consequence of the order of creation in your document. Tools>Update>Update All adds the missing “TOC2” entry because then the second TOC now exists.

The only reliable way to include the TOC heading inside the TOC is to have this heading manually created (and consequently leave the heading field in the TOC dialog empty). This is what @PKG did. Now both TOC headings appear in the TOCs.

PS: You can advantageously associate a page break in the definition of Heading 1 (and Contents Heading) in the Text Flow tab. This removes an occurrence of direct formatting.

3 Likes

thank you,i have done that.

sorry, i did not understand that last thing you said.

@ardv
In your sample file, you added manually the page breaks before the Heading 1 and Contents Heading paragraphs. Instead, you should configure these paragraph styles so that the page break is automatically added whenever you use these styles. For that, open the Text Flow tab of the styles and tick Insert in Breaks section. (But delete the manual breaks before doing that otherwise you’ll create a formatting mess.)

Direct formatting always plays nasty tricks on your back. There are of course circumstances where you can’t do otherwise, but try to minimise your use of direct formatting. Even the mandatory direct formattings are problematic.

2 Likes

Thank you very much. it is very helpful and i did not know this before, now the breaks are made automatically before the new heading.
i always used to use direct formatting but after starting using libreoffice i started using automatic styles and i find it very useful.

i tried to use that method is some of my files and i find it very useful, but there is an exception: some times the chapter before the heading ends with a small paragraph in a small area of the page and i don’t want the next chapter to start in a new page in this case. but if the chapter ends in more that 50 percent of the page i want then to start a new page.

Just an untested suggestion.
How tall is the spacing before a chapter heading? (probably not half a page) You can try to untick Add paragraph and table spacing at tops of pages in Tools>Options, LibreOffice Writer>Compatibility. Combined with Keep with next paragraph on the chapter heading and some widow/orphan tuning. This may be quite close to your specification.

1 Like

i tried what you say but it does not make what i need.
this is an example:
heading1:
heaind 2
long text
heading 2
long text
heading 2
short text
heading2

now: i need that the first heading 2 will be in the same page with heading 1
and the last heading 2 in the same page with the short text.

this is an exmaple:

there is a black page. i need to write heading 2 just after heading 1 witout any text between theme

A screenshot is worth next to nothing when it comes to such subtle tunings. Attach your sample file.

sample file.odt (13.1 KB)
this is a sample file.
i need that the heading 2 should be in the same page with heading 1. i dont want that heading 1 will take just 1 whole page.

Do not allow a page break for heading2 if you do not want it.

1 Like

i want it but not after heading1

Your sample file contains too many direct formatting (though you already have styled your document) for the suggested trick to work reliably. Rework your styles, notably define a specific style for the first paragraph after a Heading 2. Use character styles. Pay special attention to your confusing use of non-breaking spaces instead of regular spaces. Remove excess spaces at end of paragraphs.
You seem to number manually your paragraphs. No sure whether a list style or some other Heading n at appropriate level would be more convenient.

When this cleaning job is done, you can consider trying the trick to find ad-hoc settings.

1 Like

i want the heading2 page break but not after heading1. so i need to make another style for the first heading2 just after heading1? or it is better to use direct formatting?

edit (i did not see the last replay when i wrote the replay):
“Your sample file contains too many direct formatting” that’s because i copied the text from other pages. by the way i searched for an option to paste text unformatted but i couldn’t find it. is there any such option?