How can I change the table of contents to include the relevant chapters in different parts?

Hi,
Currently I have the following in my table of content:
Chapter_1
Chapter_2
Chapter_3
Chapter_4
Chapter_5
Chapter_6
Chapter_7
Chapter_8
Chapter_9
Chapter_10

I want to change the table of content to include the relevant chapters in different parts as follows:
Part_1
Chapter_1
Chapter_2
Chapter_3
Chapter_4
Part_2
Chapter_5
Chapter_6
Chapter_7
Part_3
Chapter_8
Chapter_9
Chapter_10

Thank you for your support.

Hello @Andrew_Duncan,

is this what you are looking for?

Is the part also a heading? In which case, you should write it as level 1 heading, e.g., = Part 1, then your chapter is == Chapter 1.

1 Like

Thank you for quick reply. No the part_1, part_2 and part_3 are not heading. The solution you provided works when the parts are heading.

In which case, you need some kind of additional information to construct the outline.

// Part 1
#metadata("Part 1") <part1>
#outline(..., target: selector(heading).after(<part1>).before(<part2>))

= Chapter 1

= Chapter 2

#metadata("Part 2") <part2>

Something like this maybe?

What is stopping you from making them top-level headings? It will make much more sense semantically, and as a consequence easier to solve the problem. Also, if you want help/relevant solutions, you need to provide an example how the ToC is created, not just plain text and “you guess how I did it”. Everyone would assume that the differently-named sections are headings.

Hi Andrew,
Sorry for the mistake, I need to correct something. Part_1, Part_2 and Part_3 are also heading 1.
And for example when you collapse part_1 in the table content, chapter_1, chapter_2, chapter_3 and chapter_4 shall appear. So basically, chapter_1, chapter_2, chapter_3 and chapter_4 are children of part_1 but still look heading 1.

Thank you.

So now parts are headings. And chapters too.

What does “collapse part_1” means? Where you “collapse” it?

In what way exactly are chapters children of part 1? Where exactly the chapters still look like top-level headings?

In the PDF’s Document Outline, you can only collapse sections with actual children, that appear as children. In the Typst’s outline you can style them however, but to distinguish between them and make a proper Document Outline you must use different levels for different section/heading types.