Disable numbering for heading level above threshold

607 views Asked by At

I'm adding numbering to headers with something like

#set heading(numbering: "1.1")

However I want numbering to stop for levels 3 and above.

I believe the syntax should look something like #set heading.where(??) ??, but I quickly get stuck.

2

There are 2 answers

0
Olivier On

So I found two ways : the easy one and the hard one.

Easy one

The first one is a simple show rule. The problem is that you need to set one for every level that you want to modify. In your case, you need to set one for every level above 3 that you want to use.

#set heading(numbering: "1.1")

#show heading.where(level: 3): it =>[
    #block(it.body)
]

This solution is inspired by what was done by aurghya-0 in his Project-Report-Typst.

The hard one

The hard one uses a condition on the level to decide what to do. If the level is 3 or above, only the body of the heading is displayed. If the body is under 3, then the numbering is also displayed.

#set heading(numbering: "1.1")

#show heading: it => {
    if (it.level >= 3){
        block(it.body)
    } else {
        block(counter(heading).display() + " " + it.body)
    }
}

This solution seems a good idea as you don’t need to repeat yourself but the first solution is easier and is needed if you want to change other parameters of your headings. For this reason, I recommend using the first solution.

One last thing, to simplify the examples, I omitted any other changes to the look of the headings. I let you tune those settings like you want.

0
xkevio On

This will also work but requires setting the numbering in this set-rule specifically:

#set heading(numbering: (..n) => {
  if n.pos().len() < 4 {
    numbering("1.1", ..n)
  } 
})