How to keep the document title out of the table of contents and not have the numbering of the chapters start with 0?

I have a question about numbering of headings and in outlines. I have this example document:

= Title

#outline()

#set heading(numbering: "1.")

== Section 1

=== Subsection 1.1

=== Subsection 1.2

== Section 2

=== Subsection 2.1

I would like to have this outline and heading numbering:

  1. Section 1
    1.1 Subsection 1.1
    1.2 Subsection 1.2
  2. Section 2
    2.1 Subsection 2.1

But the actual result is:

Title
0.1. Section 1
0.1.1. Subsection 1.1
0.1.2. Subsection 1.2
0.2. Section 2
0.2.1 Subsection 2.1

How can I get the expected numbering?

To get the expected result, you need to create a show rule for the headings and for the outline.

#show heading.where(level: 1): set heading(outlined: false, numbering: none)

#show outline.entry: it => context {
  let el = it.element
  if el.func() == heading [
    #let c = counter(heading).at(el.location()).slice(1)
    #numbering(el.numbering, ..c) #el.body #box(width: 1fr, it.fill) #it.page
  ] else{
    it
  }
}

#show heading: it => context {
  if it.level != 1 and it.numbering != none [
    #let c = counter(heading).at(here()).slice(1)
    #numbering(heading.numbering, ..c) #it.body
  ] else {
    it
  }
}

#outline(indent: auto)
#set heading(numbering: "1.")

= Title

== Section 1

=== Subsection 1.1

=== Subsection 1.2

== Section 2

=== Subsection 2.1

Result

heading-numbering

Notice how the auto indent is a little off, as a result maybe you could prefer another indentation.

Even though it is possible, I highly suggest to avoid this route. Everything would be so much easier if you just write Title with a bigger text size, and make every subheading 1 level higher. For a fully functional show rule you would need to handle the links in the outline, and maybe some other details that I’m not aware at this moment.

1 Like

@Olaf glad you got an answer that worked for you! Could you maybe try to revise your post’s title so others can find it easier in the future? The question guidelines recommend a complete question:

Good titles are questions you would ask your friend about Typst.

Also, please add relevant tags such as outline.

While I’m here, I’d like to second that. The title is not really meant to be a heading, and making it one requires you to recreate some built-in stuff (more than the answer showed). So if it’s an option, just style the title. You can use set document(title: ...) if you want the title to be part of the PDF in a “structured” way:

#set document(title: [Title])

#context {
  set text(1.4em, weight: "bold")
  document.title
}

FYI, you can get everything done without context and inside the heading numbering function, resulting in a more minimal solution.
Outline indentation is an implemented feature of outline.

#heading([Title], outlined: false)

#set heading(numbering: (..numbers) => {
  let n = numbers.pos() 
  if n.len() == 1 {
    return numbering("1.", ..n)
  } else {
    return numbering("1.1", ..n.slice(1))
  }
})
#set outline(indent: auto)

#outline()

== Section 1

=== Subsection 1.1

=== Subsection 1.2

== Section 2

=== Subsection 2.1
Output

1 Like

That’s a much nicer solution! I forgot numbering accepts a fuction :slight_smile:

It is as Anemona-Anonima said at the beginning. It is wrong to treat the title of the document as a heading. I did it this way because I know it from Markdown and AsciiDoc. If you don’t do that, all the problems disappear by themselves.