Conditional page count in LibreOffice

Almost six years ago I instructed how to conditionally show page numbers in Microsoft Word. The idea is to show the page number and total page count only if there are more than one page in the document. If the document has only one page, it looks more beautiful without unnecessary page number of one. If the document has more than one page instead, it helps the reader keep and read the pages in correct order the writer intended. Word processing applications have automatic page numbering feature, which increases and adjusts the numbers while writing the document. LibreOffice Writer, among others, has special PAGE field that shows the current page number when inserted anywhere in the document page. When the page count increases the number field updates automatically. To ensure the reader has all the pages the document usually shows the total number of pages as well printed next to the running number. The total count can be seen in brackets, for example: 1 (8). Writer has PAGES field in Statistics category to show the total number of pages.

I wanted to add automatic page numbering as well as the total number of pages in my documents. I also wanted to show the numbers only when the document has more than one page. This feature required conditional page numbering, which was a bit tricky to implement with Writer. One solution is to use sections and conditionally hide them depending on the current field values. In this approach the document requires two sections: one is shown when the document has only one page and the other where there are multiple pages. Here are the steps to do the trick:

  1. Place the cursor where you want the page number to appear. The page number is usually displayed in the header area. Note that sections occupy the whole row thus spreading all the way from left to right. You need to enter all the text you want to show in the section even though part of the text must be duplicated in the next section.
  2. Select Insert and then Section...
  3. Name the section, for example, Onepage and check the "Hide" option. Enter Page > 1 in the "With Condition" field. This condition will hide the whole section when page count value is greater than one meaning that there are more than one page in the document. Click Insert button to insert the section in the header.
  4. Enter the text you want to appear in the section when the document has only one page. In this case you may want to omit the page number.
  5. Place the cursor under the section and select again Insert and then Section...
  6. Name the second section, for example, Multipage and check the "Hide" option. Enter Page EQ 1 in the "With Condition" field. This condition will hide the whole section when page count value is equal (EQ) to one meaning that there are only one page in the document. Click Insert button to insert the section in the header.
  7. In order to edit the Multipage section add one page by pressing Ctrl+Enter simultaneously. This will hide the first, Onepage section and reveal the second section for editing. If the sections do not update, press F9 to update the fields.
  8. Enter the text you want to appear in the section when the document has more than one page. In this case you may now display the page number and the page count. Note that some texts must be written twice because the whole section is hidden, not just the page number.

If you want to edit both sections at the same time, simply uncheck the Hide option in the section settings window. Open the Navigator by pressing F5. Expand the Sections group and select Edit on the section with the other mouse button.

Displaying page numbers conditionally in LibreOffice Writer requires some extra thinking compared to Microsoft Word. Using sections and altering their visibility depending on the page count does the job.

Julkaistu keskiviikkona 16.11.2016 klo 18:43 avainsanoilla ohjelmistot ja ohjelmointi.

Edellinen
Tähdet ruudukossa - osa 2
Seuraava
Valerian-elokuvan traileri