Chapter numbering defined by text fields - variable ignores level of numbering

Open the attached document.
chapter_numbering_variables.odt (140.9 KB)

There are some headings. Numbering through “Chapter Numbering” has been defined. Works as expected.

Now there should be created headings, which shouldn’t appear in TOC. For this headings I created a numbering this way:


Note: level for “Numbering by Chapter” is set to 3.
First it seems to work. But it will only work when it is following to “Heading 2”. If it is following “Heading 1” the number will be for level 2 and if it is following “Heading 3” the number will be level 4.

Might be I understood this wrong, because I couldn’t find a description for this. Also might be it is a bug. I will wait fore some comments here before writing a bug.

Note that the “3” does not define the level of your numbering in the number range, but the count of levels of “headings” considered for the prefix. So, the “3” means up to three levels of headings will be prepended before this number, like “Heading1.Heading2.Heading3.SequentialNumberOfTextRange”.

You are right. I have to set it to “2” for maximum number for getting “Heading3” constructed in this way. This should prevent for getting numbers longer than expected…

Number Range is not intended to number “lists” but to number drawings, figures, images, … It is in no way a means to interfere with chapter numbering.

The Numbering by Chapter parameter provides a way to alter the number in order to “integrate” it with chapter numbering. When you enable it, chapter number up to the requested level is prefixed to the number range. It also tells the number range is reset whenever the designated level changes (which is also implied for lower levels per definition of chapter numbering behaviour).

Your problem is not to number your headings but to prevent some of them from being retained in the TOC. This is completely different. Your specification lacks an important requirement: should this “omitted” heading be numbered in continuity with the others (thus creating “holes” in the TOC) or can it be unnumbered, out of order, …?

I assume your question is not simply to restrict the TOC to the first n levels but you want some Heading 2 be omitted from TOC while all others are included. The “simplest” solution I think of is based on cross-reference insertions and one character style for the “omitted” heading.

EDIT 2023-01-02
Solution to drop “trailing” headings from TOC

From a long exchange through comments, it appears that OP’s specification may be summarised as follows:

  • headings are numbered according to their level, without exception
  • in the part defined by a Heading m up to the next Heading m, there are Heading m+1 headings to subdivide the part (and possibily deeper headings)
  • it is requested that the last k Heading m+1 are not collected into the TOC while all those preceding are collected into the TOC

The difficulty comes from the fact that Heading m headings are treated differently inside the same level.

What is needed?

  • the unaltered Heading n so that chapter numbering is not tampered with and behaves normally
  • a clone of Heading n; call it Heading n No TOC
    You create it by right-clicking on Heading n in the side style pane and coosing New. Don’t modify anything (so that any change you make to Heading n is also propagated to this new style. Just go to Outline&List to make sure the paragraph style is attached to Outline level Text Body
  • a character style named Invisible
    The only attribute you set is Hidden in Font Effects tab.

Procedure

When you want to insert a “not-in-TOC” heading

  1. type it as usual
    It will get its number as expected
  2. select the whole heading and apply character style Invisible
    To avoid losing visibility and editing possibility, it is highly recommended to enable the view hints Tools>Options, LibreOffice Writer>View: in Display fields, tick Hidden text
  3. to make the “not-in-TOC” heading reader-visible, use a Heading n No TOC paragraph immediately below the now hidden heading and fill it with fields
    • Insert>Cross-reference, Type Heading, Selection your heading, Refer using Chapter
    • type the same separator which follow the heading number (space, tab, newline, …) so that your fake heading will have the exact same look as the hidden one
    • Insert>Cross-reference, Type Heading, Selection your heading, Refer using Referenced text

Operating considerations

You say the recipe will be put into the hands of ordinary writers.

Create a template file where all styles can be stored and made available to any document based on the template.

The three steps may look tremendously ununderstable to the majority of your authors which are probably totally unaware of styles and likely direct format their documents. Here direct formatting means failure.
So create an auto-text with dummy heading contents. The whole construct invisible fake heading, cross-referenced user-visible heading and a Text Body empty paragraph can be generated by AutoText.
You just have to tell your people to fully select the “invisible” heading (it displays with a dotted underline) and to overwrite the real heading contents. The user-visible heading is automatically updated.

Don’t hesitate to ask for clarification or improvement.

I have written the description, because other users (German ask and mailing list) asked for a numbered entry as heading, which shouldn’t appear in toc. The numbers created as Chapter Numbering won’t be set to numbers with “holes”, because the Chapter Numbering will ignore all these entries with a special variables numbering. The only problem, which users will have, is: There would be duplicates of numbers, if the 2 different headings are mixed in the same level.

Just tell which is your schema. The solution may be very simple

Schema A

1. Level 1
1.1. Level 2
1.2. Level 2 not in TOC
1.3. Level 2
2. Level 1
   TOC
1. Level 1 ...............1
1.1. Level 2..............1
1.3. Level2 ..............2
2. Level 1 ...............3

In this scheme, the headings are just ordinary headings, some of them are omitted from the TOC creating numbering “holes” in the TOC.

Schema B

1. Level 1
1.1. Level 2
     Level 2 not in TOC
1.2. Level 2
2. Level 1
   TOC
1. Level 1 ...............1
1.1. Level 2..............1
1.2. Level2 ..............2
2. Level 1 ...............3

In this scheme, the “omitted” headings are unnumbered or numbered in a sequence independent of chapter numbering. The TOC has no holes.

Just tell which is your preferred schema (or make the necessary adjustments) and I’ll propose you a very simple solution which does not need a number range. Usually a pragraph style duplicating the corresponding Heading n is sufficient when it is not attached to an outline level.

The only schema I will see (for those, who will use this, ant want the numbering) isn’t “Schema A” or “Schema B”. Numbering is what the posters (in German ask and mailinglist) will have.
So:

1. Level 1
1.1 Level 2
1.2 Level 2
2. Level 1
2.1 Level 2 not in TOC
2.2 Level 2 not in TOC
3. Level 1
3.1 Level 2 
3.2 Level 2
3.3 Level 2 not in TOC
3.4 Level 2 not in TOC

So: Never follows a heading, which should appear in TOC, in the same level as a heading, which won’t appear in TOC. All other will give duplicates in numbering, and numbering for every header has been asked for.

So to make things explicitly clear:

  • all headings are numbered
  • “omitted” headings can occur only after “included” headings and no “included” heading is allowed once we have an omitted heading.

Right

1. Level 1
1.1. Level 2
1.2. Level 2 not in TOC
1.3. Level 2 not in TOC
2. Level 1
2.1. Level 2
3. Level 1
3.1. Level 2 not in TOC

Wrong

1. Level 1
1.1. Level 2
1.2. Level 2 not in TOC
1.3. Level 2
2. Level 1
2.1. Level 2 not in TOC
2.2. Level 2

If you confirm we now have a “complete” specification, I can propose you a solution which use chapter numbering, one character style to eliminate headings from the TOC and one cross-reference to have fake-headings in the text. And best property of my solution: it doesn’t mix list numbering (e.g. chapter numbering) with a number range to get quirled result.

Yes, all other solutions will give double numbers or holes or something like that.

Solution must be easy to use for others. I’m not the one who wants to use such a construction. I’m only searching for a solution and at this moment the solution with the numbering seems to work for me. Have set it in a macro together with format for the paragraph and following tabulator after setting the number and it works.

If you know another solution I will have a look.