19

How do I hide all the sections and subsections of one chapter from the contents page?

What I want is if I have this:

\documentclass[12pt, a4paper, draft, titlepage]{report}

\begin{document}

\tableofcontents
\chapter{This chapter is listed in the contents page}
\section{So are all its sections}
\subsection{--- and subsections!}

\chapter{This chapter name is listed in the contents page}
\section{But this section doesn't appear on the contents page.}
\subsection{This section doesn't appear on the contents page either.}
\end{document}

I want it to appear like this: How I want the image to appear

But of course, it appears like this: enter image description here

Is there any way I can hide all the sections and subsections of that specific chapter?

1 Answer 1

26

You can change the value of the counter tocdepth mid-document, writing it to the ToC at the appropriate spot. This allows you to vary what shows and what doesn't show.

enter image description here

\documentclass{report}

\begin{document}

\tableofcontents

\chapter{This chapter is listed in the contents page}
\section{So are all its sections}
\subsection{--- and subsections!}

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
% From this point on, only show up to \chapters in the ToC

\chapter{This chapter name is listed in the contents page}
\section{But this section doesn't appear on the contents page.}
\subsection{This section doesn't appear on the contents page either.}

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
% From this point on, only show up to \subsection in the ToC
\chapter{This chapter is listed in the contents page}
\section{So are all its sections}
\subsection{--- and subsections!}

\end{document}

Sectional units have the following "level":

  • -1 = \part
  • 0 = \chapter
  • 1 = \section
  • 2 = \subsection
  • 3 = \subsubsection
  • 4 = \paragraph
  • 5 = \subparagraph

Other document classes may offer different levels.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .