Adding multiple fields in a header (in LO writer)

I am trying to display the page number, chapter title and subsection title all in the header. I have styles set for chapters and subsections. I already have a page number field set. I am looking to have the Chapter titles aligned to the left, page numbers in the center and subsections to the right.

I should also mention that I have my chapter titles set as ‘Heading 1’ , sections as ‘heading 2’ and subsections as ‘Heading 3’. I did this for my TOC and not sure if that matters or not nor if it was the right thing to do. It was my work around to get the TOC to display what I wanted as I couldnt figure it out at the time.

Thank you

All paragraph styles used by default on headers have two tab stops defined: a first one centered at the page center and a second one at the right of the page with right alignment. You just need to insert the first content (page number), press tab, insert the second content (chapter field with “level 1”), the second tab, and finally the last content (chapter field with “level 2”). To insert those fields, go to Insert → Field → More Fields → Document tab.

(If you are interested in learning more, check my book about Writer :wink: )

Thank you very much. That definitely will work. I must have not set something correctly though. I can add level 1 and the page numbers successfully. When I add the level 2 it just displays the same thing as level 1 (which is chapter 1 for example). Where do I set where the levels pull data from? I am assuming that I don’t have level 2 set to my heading 2 style.

Which styles define which levels can be defined on Tools → Chapter numbering. By default, Writer uses Heading 1 to 10 for levels 1 to 10, so it should work without problems. However, unless the second level heading is at the very beginning of the page (or in a previous page), the header will not pick it up until the following page: maybe that’s the problem you have. If not, please start a new thread describing the problem and attach a sample file so we can see what’s going on.

Indeed, the level 2 was not set correctly for some reason. I did get them to show up but just as you described the second level heading doesn’t always show up the way I want it to (usually always at new chapters it will have the precious section title)
Is there a way to add breaks to headers?

When inserting the Chapter field into the Header you can select the Level.
These levels correspond to the Levels you set in Tools > Chapter Numbering.
So selecting level 3 will display your sub-section (Heading 3).

.

If this answered your question please check the checkmark at left.

.

Guess I should have refreshed the page first before posting. :slight_smile:

It’s the thought that counts! Thank you

In addition to @RGB-es’s answer, I point out that your requirement is quite complex, i.e. chapter and subsection title might be long enough to cause text to flow to next line, misaligning subsequent elements on the wrong tab stop.

In such a case, I opt for a table so that I can control exactly what goes where. See example below.

This is the “code” in the table

image description

resulting in

image description

where all elements come from field insertion (from File>Properties, except chapter title and number from the most recent Heading 1). Only fixed strings like “Project” or “Language” are manually written. Even the book title is a “property” so that it is identical on the title page and in the header. Note: page numbers are inserted in the footer; it is only a matter of personal preference.

Chapter and subsection

Field values to be inserted in the header are computed when the page is created. At this time, only the first paragraph is available. Of course, content of previous pages is also known. This context is used to determine field values.

You have no problem with Heading 1 because you usually cause a page break so that it is the first paragraph on the page. Either the first paragraph is a Heading 1 and you get the new chapter title, or it is another paragraph and you get the current chapter value (the most recently set Heading 1 if it exists, see below).

The only difficulty arises if you precede your Heading 1 with some introductory text or quotation: this will cause the chapter title to be lagging one page.

Situation is more complex with Heading n, n>1. General algorithm is the same: context at first line is used to compute field values. However, you may not have yet a Heading 2 (you are at the very early beginning of the chapter). In this case, LO Writer has chosen to return the closest containing Heading n (e.g. you request Heading 3 but it does not exist, then Writer attempts to return the containing Heading 2 if possible, otherwise Heading 1, by default nothing).

This is why you get twice the chapter title when there is no subsection yet. The general algorithm also returns the known Heading 2 at the beginning of the page (reverting to Heading 1 if there is none yet), eventhough you have a Heading 2 change inside the page.

Field insertion in the footer shows the expected results because there is no need for forward looking in the page, though we get there the last section titles (not the first in the page). But it is quite unusual (and disturbing) to display headings at the bottom of the page.

Great answer, just a little too technical for me to fully grasp, especially the beginning. I get the gist of it just not sure I fully understand how it can be resolved. What is the remedy for this if any?

Remedy: as you promised, learn styles.

My trick is based on the fact that a header is nothing but another print area. You can put anything inside, be it a quite large subdocument (which will be repeated on every page) with as many paragraphs, frames, pictures or other objects you want. To give more structure to my header, I insert a table there. The net effect is the chapter title, whatever large it is, will never extend to the left or right column. It will always remain in the center column, with eventual line wrapping.

As you can see, I have inserted the book title and the current chapter title (with its number) in the center cells. Cells in outer columns contain document “maintenance” information, like document revision number and the software application it is related to.

Not shown: thanks to the power of styles, the header on the first chapter page does not repeat the chapter title because it is the first paragraph after the header.

I tried adding the table in the header. That is a great idea. much easier to control the positioning. I still can’t fully understand the example you gave . I think I get the main concept but I don’t really know exactly what Is going on. If you get a chance could you remake the example you have up there using generic words like Book Title, Chapter 1, Section 1 etc… I am really new to this stuff so I am kind of confused as to what is going on.

We could continue on private mail since discussion is turning to really personal needs and explanation which are no longer general enough to be logged here. I’ll create a dedicated @ddress (to tame spam attacks) and report it here.

That would be very much appreciated.

Just created page74010 (dash) asklo (at) yahoo (dot) com

Replace (…) by the punctuation it describes. This is only a small obfuscation against the robots crawling for @ddresses.