Page count just for the current section?

My document has three sections: title page, contents, and main body.

I want the footer in the main body to read “Page X/Y”, where “Y” is just the number of pages in the main body section, not the number of pages in the whole document. Otherwise the last page will say something like “Page 50/52”, and there won’t be any pages 51 or 52. Any way to do count the number of pages just in the current section?

Hi,

there are some possibilities to do that.

  • Insert a variable in the footer (name it like PageCount and add or diminish some value - here: PAGE-2)
    (see attached file - screenshot included)
  • insert as last “character” in the text the field page number, define as a cross reference and set the cross reference into header or footer. Be aware to format the field as hidden.
  • insert as last “character” in the text the field Set page variable - offset -2, define as a cross reference and set the cross reference into header or footer. Be aware that the field is hidden when inserted (grey background).


    PageCount1BeginsPage3.odt (54.0 KB)
1 Like
  • first proposal PAGE-2
    I’d qualify it as “not reliable”. Built-in variable PAGE is the total count of page (as displayed in the bottom status bar or in statistics). Therefore it is not valid to show number of pages in a single chapter if this is desired. Works only globally.
    Also the literal -2 will not automatically adjust to edits in cover and TOC. It requires manual fix after changes.
  • second proposal page number field at end of text
    It can be simplified. Just Insert>Cross-reference, then Set Reference. No need to hide the marker.
    Where you want the page number of this position, you Inert>Cross-reference, Insert Reference and you can choose between page number or chapter number (though not relevant for your purpose).
    If you restart the page number in each chapter, you have the chapter page count.
  • third proposal value with an offset
    As a simple rule of thumb, never set an offset (unless you totally know and master tje consequence). Offset does not change the page number. It references another page. Thus, it is not what you think it is and give wrong results mainly at both ends of the page sequence.

IMHO, only the second proposal, once simplified, is the solution.

2 Likes

Yes, thanks very much @Grantler and @ajlittoz , the second approach works. One issue remains however.

I went to the end of the document, and used “Insert > Cross-reference”, then chose “Type=Set Reference” and chose the name “Last_Page”, then clicked the “Insert” button. However, nothing was displayed to show the reference was there.

I tried turning field names on with “ctrl-F9” or “View > Field Names”, and it switched field names on but still did not show the cross reference in the document.

Nevertheless, I went to the position of “Y” in “Page X/Y” in my document, and then selected “Insert > Cross Reference” and chose “Type=Insert Reference”, “Refer Using=Page number(unstyled)”, highlighted “Last_Page” and clicked “Insert”. The page number showed up as the number of pages in the main body of the document. When the number of pages in the main body changes, I have to select the whole document and do an “F9” to update the fields, but that is relatively easy.

So the one issue is I cannot see the cross-reference in the main body, where I set it, as the last character of the document. If I cannot see it, I might delete it by mistake. Is there some way to make sure the cross reference is displayed in the main body of my document where I set it originally?

My second proposal to set in the page number as hidden character and set the cross reference on it displays the field if you have chosen Display Fields | ☒ Hidden Text (menu Tools…)

1 Like

Have you enabled View>Field Shadings or Ctrl+F8 ?

1 Like

Thanks @Grantler and @ajlittoz . Selecting “Tools > Options > LibreOffice Writer > Display Fields > Hidden Text” did not change anything. However, selecting “View > Field Shadings” or “ctrl-F8” does show the cross reference at the end of the document. It just looks like a single space character, with grey shading, no name or other identifier. But at least I can see it. Thanks much.

Thanks @Grantler and @ajlittoz . Now that I understand it, I have tried using a bookmark, which seems a bit more natural than a cross reference, and has a small advantage that the bookmark is visible as a light grey character that looks like a capital “I” like this: image

Please correct me if the cross-reference has some advantage. That is, for the bookmark solution I do the following:

First I create separate sections with “Insert > More Breaks > Manual Break > Page Break”, choose the page style of the next section I want, and check “Change Page Number” and set it to 1.

Then I go to the end of the document and choose “Insert > Bookmark”, and name the bookmark “LastPage”. I turn on “View > Field Shadings” or “ctrl-F8” and it shows up as a grey capital “I”.

Then I go to the Y position in “Page X/Y” in the footer of the main body, and choose “Insert > Cross Reference” and choose “Type=Bookmarks”, “Refer Using=Page number(unstyled)”, highlighted the bookmark “LastPage”, and clicked “Insert”. The page number shows up as the number of pages in the main body of the document.

I’m not sure if it will always be true, but I also noticed that with a bookmark the page number updates automatically when a new page is added to the main body - so far I have not had to select the whole document and do an “F9” to update the fields.

Does this all seem ok to you?

Bookmark and cross-reference location are equivalent. Initially, I used bookmarks to “name” a given location then reference it through Insert cross-reference.

Later, I realised there is a semantic difference between them. A bookmark is intended for Navigation within your document while a (Set) Reference involves your document topic, without implying scrolling to it when you sit at your computer. This is a matter of “logic” and flags the location as either a target in your workflow, or a source of information for your contents.

There is also a behaviour difference as you noticed.

By design, inserted reference data is not automatically updated because it could involve a lot of text reflow. Here, reference data means not only page number but also chapter number or reference text. In the two latter cases, number of inserted characters may vary a lot which may have important consequences on the rest of text, recursively causing update to other cross-references. Therefore update is triggered by user (or save) when it is known text is in a “stable” state.

However, my tentative explanation (I am not a developer) can be defeated because you can also insert chapter number and text from a bookmark and thus cause a dramatic reflow in some cases.

In the end, it is a matter user preference. Bookmarks and References (locations) are listed under different headings in the Navigator.

1 Like