2

The title pretty much says it all. I have a long document, which contains chapters, sections, subsections.... The table of contents should only include sections for most of the chapters, but subsections within one specific chapter like this:

Chapter 1
    section 1
    section 2
Chapter 2
    section 1
    section 2
Chapter 3
    section 1
        subsection 1
        subsection 2
    section 2
        subsection 1
        subsection 2
Chapter 3
    section 1
    section 2

Is this possible? If so, how does one do it?

[Edit: some of the sections in e.g. Chapter 1 will also have (numbered) subsections, but I don't want them to show up in the table of contents. Basically, I want the TOC depth to vary from chapter to chapter.]

  • 1
    What happen if you use starred versions of the subsections you don't want to show in the TOC? – Aradnix Sep 19 '14 at 17:32
  • That is, use \subsection* for those subsections you don't want to be displayed in the TOC. – leo Sep 19 '14 at 17:35
  • I want all subsections to be numbered within the text - only some of them should be excluded from the TOC. – Daniel Miller Sep 19 '14 at 17:35
5

you can reset the tocdepth in the toc by inserting change commands in appropriate places.

say you start with \setcounter{tocdepth}{1} to include nothing lower than sections. to reset this in another chapter to include subsections, insert this command just after the \chapter command for the relevant chapter:

\addtocontents{toc}{\setcounter{tocdepth}{2}}

the command needs to go into the file with the chapter data; if you put it into your main file, and use \include to pull in the chapter files, latex will delay its application until after the \included file, so it's better not to try to do this from the main file. as for where it goes in the chapter file, it can be put anywhere before the first section that is to be listed. if you put it right after the \chapter line, it'll be easy to remember and to find if you decide later that you want to change it.

you can restore the original setting in the next (or next applicable) chapter with another \addtocontents insertion.

there are other ways to limit the scope of the tocdepth setting, but this is probably the most straightforward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.