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.]

• 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

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 `\include`d 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.

• In case anyone else has the same problem with this that I did: if you are using `mathtools` then `\setcounter` needs to be `\protect`ed, as mentioned at tex.stackexchange.com/a/65031/535 . – Mike Shulman Sep 23 '15 at 4:33