How to produce a heading numbering 1.0.0 as first level?

Hi,
i am struggeling with a very specific format wish, which might be a bit unusual:
I want my heading to be numbered like this:

1.0.0 My First Lvl 1 Heading
1.1.0 My First Lvl 2 Heading
1.2.0 My second lvl two heading
1.2.1 A third level Heading!

I tried a lot of things but I am quite new to Typst and did not archive anything close to it. The heading should be shown in the outline like this, too.

you can use a custom numbering function. within it, you can just pad the number array with zeroes and delegate the formatting to the numbering function.

#set heading(numbering: (..ns) => {
  if ns.pos().len() <= 3 { ns = (..ns.pos(), 0, 0).slice(0, 3) }
  numbering("1.", ..ns)
})
5 Likes

I mean, at this point just inline it:

#set heading(numbering: (..ns) => {
  numbering("1.", ..(..ns.pos(), 0, 0).slice(0, 3))
})

4th+ level would look ugly anyway, unless you append yet another zero, but this will strip deeper levels if exist.

Thank you for your solutions! As I didn’t know how exactly the numbering function works, I was a little bit helpless.

1 Like

https://typst.app/docs/reference/model/heading/#parameters-numbering

https://typst.app/docs/reference/model/numbering/

Did you read this?

I did and not only once.
But there is a lot of syntax for a newbie, and what I find was completely missing, was the hint, that an array is generated for the numbering and how it is built. For that reason it was not possible for me to use any of the array operations.

1 Like

You need a sentence about number array generation from element counter in Numbering Function – Typst Documentation? Or a full section with some sort of explanation?

I think at least a sentence is required, but I would prefer a more detailed section or an example which explains it.
For me it was unclear how exactly the heading numbering worked (providing an array), and therefore it was unclear how to access the numbers.

Can you create a docs issue, explaining what’s missing?

https://github.com/typst/typst/issues/new?template=3-docs.yml

1 Like

I will but it might take a few days. I am going to inform you when done

1 Like