How to: chapter numbering in heading as a field

Hello! How can I automatically number my chapters in the heading text?

What’s the goal
My document is made of the following pages:

  1. Prologue
  2. Chapter 1
  3. Chapter 2
  4. Chapter X

I want the number after “Chapter” to increase automatically each time I copy paste the title.
How can I get the chapter number as a field, starting from 1 at Chapter 1 (skipping Prologue) for every time the Chapter heading style is used? Because I’ve only made that style when I name a chapter.

My styles tree contains the following:

  • Heading 2 (unused)
    • Heading Chapter (inherits, actually used)

What I tried
I’ve found a field called Heading → Heading Number but when I use it it’s empty.

Your specification is ambiguous: do you require double numbering? Once in ordinary numbers at left and a second one at righr either in ordinary or Roman numbers?

This is possible but at the cost of a heavy manual operation for every heading.

To provide helpful answer, please provide OS name, LO version (exact release number not “the latest”) and save format.

This field returns “empty” until you have activated heading numbering. Have you configured it?

As requested by @ajlittoz here my specs:

Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac
CPU threads: 12; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Vulkan; VCL: win
Locale: it-IT (it_IT); UI: en-GB
Calc: CL threaded

Hi @ajlittoz what I want is a field that shows the number of the current chapter, and each chapter starts with an specific heading style.

Honestly regardless how to achieve that I’m not sure. It is possible to track how many heading exists at a specific paragraph or how many times the heading style has been used at a specific paragraph? I just want to automatically count the chapter title.

It is possible to export my heading style? If it is I would like it to share it to you so you can take a look at it.
However my header style has the following configuration regarding heading numbering.
I think it’s detected as an header because when I export to PDF I get the bookmark to the header, but using the Heading Number field it’s still empty.

Regarding the question about heading numbering I have activated this option under Line Numbering but that field is still empty. However when I export to PDF the chapter title are seen as bookmarks so maybe something it’s working.

If there’s something more you need please let me know. :slightly_smiling_face:

@ajlittoz here I’ve made an example document with the layout of my original document and the style configuration I’ve show in my previous image. Hope this helps.

example.odt (8.5 KB)

If the Chapter don’t have specific names you could set Heading 2 (or even Heading 1) as a paragraph style. See attachment.
.
exampleChapterNumberingGrantler.odt (8.8 KB)
.

Wow! This is exactly what I’m looking for. Could you please tell me how did you do it?

I tried to replicate the same style and bullets configuration but on my original document I don’t get the same result. I see when I update the text “Chapter” with something else it also updates everywhere so that’s really good.

I can’t copy directly from your document because apparently the last part of automatically updating the chapter text doesn’t work if I do it that way.

Thank you very much.

The provided sample file shows you tried to replace the existing chapter numbering feature (named more generally Heading numbering because it does more than simply addressing “chapters”) without mastering the basic functionality and its consequences.

There are several flaws in your configuration, aggravated by the fact you added direct formatting over your styles.

So let’s start with a few words of context.

In Writer a heading is usually intended to be collected in a TOC (table of contents). For that, it is flagged as attached to an Outline level, defining its position in the heading hierarchy. This is independent from numbering.

A paragraph is automatically numbered when it is made a member of a list. This is done with a list style. Since the list of headings is quite unique in a document, Writer has dedicated a protected internal list style for this. It is “protected” so that you can’t mix “ordinary” lists with headings and thus avoid creating conflicts or messing up numbering. This also means you must not overspecify heading numbering by adding manually list numbering over a heading. The only way to access heading numbering is through Tools>Heading Numbering.

In your sample file you enabled Include this paragraph in line numbering (note: “line”, not “heading”). This is yet another feature. In legal documents, like patents, you frequently need to add line numbers inside the margins to be able to reference words or sentences through this line number. This is the role of the line numbering feature which also needs to be globally enable and configured in Tools>Line Numbering.

Your Chapter Title inherits from Heading 2 but as you can see in its Outline & List tab, it is not associated to any list style (No List) because the “slot” is already used by Heading 2. Moreover, you detached it from its Outline level (None). This latter setting is “compensated” by direct formatting you apply manually to every heading!

The best you can do is to use built-in Heading n which are already factory-configured adequately, except for numbering. Built-in styled are “sacred”. You can customise them to your preferred appearance.

Avoid twisting the hierarchy. Why do you start your chapters at level 2? Have you higher headings such as “Part” or “Volume” at level 1? Starting a hierarchy deeper than level 1 is a fault of logic. If the reason is only font size, customise Heading 1.

Chapter numbering is enabled and configured with Tools>Heading Numbering. You can even automatically add “decorations” around the number such as prefixing with "Chapter " and suffixint with " - " or “.”. The only point to care about when your headings are reduced to their number is to make sure that the paragraph contents is not empty. At least, type a space. Due to !@#*?! compatibility rules with M$ Word trying to “fix” text typed by badly-educated users (read: people influenced by wrong Word-induced workflow based on direct formatting), empty headings are eliminated. So make sure minimal headings are never empty.

One last word. Your sample shows you chapter narrative is styled Default Paragraph Style. This is wrong. The standard styl for narrative is Body Text. It is automatically set after Heading n. In Writer, *styles are organised hierarchically in a tree-like structure with inheritance. Default Paragraph Style is the ultimate ancestor of all styles. What you change there propagates to all others (if they don’t override the changed parameter). Consequently Dft Para Style is the ideal location to set your preferred attributes to give your document a personal look.

Hi. So I got a solution from @Grantler which is really close if not exactly what I’m looking for.

About your advices.

  • I preefer to not touch the original styles an rather make a new style that inherits for what I need to use. I preffer heading because they are ordered and shows their bookmark when exported to PDF and on my libreoffice works with custom styles too if I do this. Also I give much specific names such as Chapter Title and Chapter Subtitle to make it more obvious.
  • Maybe I got confused between Heading Numbering and Line Numbering, sorry.
  • I’ve changed inheritance of my chapter title style to Heading 1 and it didn’t break the document and his PDF export. That was an accident from previous changes of the document I’ve left.
  • I’m not using Default Paragraph Style as my text body, don’t worry. :upside_down_face:

If you want to use your heading style, attach it to the heading numbering list:

  1. open Tools>Heading Numbering, Numbering tab
  2. for the level you want to use, change Paragraph style to your preferred para style, i.e. Chapter Title from the drop-down menu
  3. OK

As already mentioned, built-in styles are there to help as examples of (rather) well-designed styles. In particular, Heading n are already pre-associated to heading numbering. All you have to do is to customise font face, size, spacing, alignment, … to your needs.

If you want to replace the existing collection, read thoroughly the Writer Guide to understand the interactions between parameters and features. Replacing Heading n is not that easy if you require full functionality from your ersatz.

And, above all, DON’T MIX STYLING AND DIRECT FORMATTING.

1 Like

Ok. Figured out, thanks to @Grantler for the solution and @ajlittoz for the advices.

Here how to do it:

  1. Create a new paragraph Right Click → List → Bullets and Numbering
  2. In Customize tab select level 2 or any other level that isn’t the first.
  3. Write on Before something like Chapter and on After clear the field.
  4. In Position tab configure everything to 0 mm and Followed By set to Nothing.
  5. Press Ok and now it should display Chapter 1
  6. To use it on other headings Right Click → Clone Formatting and paste it on another header, even if you modify the bullet style from one header it will propagate to everywhere it has been cloned (maybe bc it’s a copy of the style reference).

The example of @Grantler automatically applies the numbering style when the header style is selected, idk how to do that. I haven’t managed to figured it out. But for now these steps worked for me flawlessly.

I’ll share again the example from @Grantler because that’s good enough to see the result.
exampleChapterNumberingGrantler.odt (8.8 KB)

PS IMPORTANT: Figured out how to configure it on the header style directly!!

On the styles list on the style of your choice Right Click → Edit Style → Outline & List → Edit List, you have the same bullet menu editing panel from my last message. Do everything from step 2 and skip last step.

PS 2: Could be possible to change the title of this topic? Tecnically it’s not a field. It should be called “How to: auto chapter numbering in heading style” to fit better.

When you create a dedicated list, don’t use this generic one-size-fits-all command inherited from Word supposedly to ease transition. Writer will be at hard effort to guess the extent of your heading list if you also have other “ordinary” lists in your document. The numbering will be mixed and inconsistent without possibility to fix. The solution is to create a custom list style reserved to this usage (the same as Writer does with its internal reserved outline list style).