16

Hiya, Is it possible to set the \setcounter{tocdepth}{..} for one chapter only?

The default depth is fine for the entire document, except for the last chapter- I only want the chapter title to appear in the table of contents (all sections, subsections etc should not appear).

I could adjust all of my sections to use an asterisk, eg \section*{...} which will cause them to not be numbered and not show up in the ToC, however I want these sections to be numbered! (I have references to these numbers elsewhere).

I have tried placing \setcounter{tocdepth}{1} to the chapter I want this to apply to, and have tried adding it to my main tex file before the \include of that chapter, doesn't seem to work (I guess because \maketitle has already been called by that stage?)

Any suggestions?

1 Answer 1

21

If I understand you right, the code below should do what you want.

\documentclass[11pt,a4paper,english]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}

\begin{document}
  \tableofcontents

  \blinddocument

  \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
  \blinddocument
\end{document}

Setting the counter tocdepth to »1« would also show the sections.

One should note that this will change the tocdepth for the rest of the document. Simply using the same command you can set the depth to what ever you wish for following chapters.

4
  • Damn. I missed posting this answer by a few seconds. I think you need 1 to see sections and 2 for subsections, at least in the book class. Commented Oct 13, 2010 at 21:07
  • 9
    It would also help the relatively uninitiated that the \blindtext package and the \blinddocument commands are just for generating dummy, testing texts. They are not part of the solution. Commented Oct 13, 2010 at 21:59
  • Thanks, that works perfectly. And thanks also Willie Wong, that would have been pretty confusing figuring out why all my content suddenly changed... :p Commented Oct 14, 2010 at 20:03
  • It's been very long, but just complementing @Thorsten Donig 's answer: let's say you did what he recomended for a last chapter/appendix (which would be the only one with this setting in the whole document) and set for said chapter \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}. Then, in the document pdf, anything "below" chapters wouldn't show up in the side tab. To fix this, after said chapter, set the tocdepth back to what you want normally in the rest of the document. Went through this issue just now and fixed it like that, so I wanted to share with anyone that might have a similar Commented May 5, 2024 at 18:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.