TOC hide numbered subsection but only under one section

I have a document that looks like this

\documentclass{book}

\begin{document}
\tableofcontents

\chapter{Intro}
\chapter{Body}
\section{A section}
\subsection{A sub-section to number and include in TOC}
\subsection{Another sub-section to number and include in TOC}
\section{Another section}
\subsection{Number but do not include in the TOC}
\subsection{Another to number but do not include in the TOC}
\section{More}
\subsection{A sub-section to number and include in TOC}

\end{document}


I'd like to number but hide the subsections under one particular section from the TOC. Using \subsection*{} hides them but also causes them not to be numbered in the document.

The reason for this is because of the number subsections under one particular section. It would just make the TOC too long and isn't really necessary.

• Does adding \setcounter{tocdepth}{1} before \tableofcontents give you what you want? – Schrödinger's cat Nov 14 '19 at 0:21
• No that removes all subsection. I would like to remove only the subsections under 2.2 from the TOC – agf1997 Nov 14 '19 at 0:32

You can add the \setcounter{tocdepth}{<level>} inside the section commands to locally change the depth of the table of contents.

\documentclass{book}

\begin{document}
\tableofcontents

\chapter{Intro}
\chapter{Body}
\section{A section\setcounter{tocdepth}{1}}

\subsection{A sub-section to number and include in TOC}
\subsection{Another sub-section to number and include in TOC}
\section{Another section\setcounter{tocdepth}{2}}

\subsection{Number but do not include in the TOC}
\subsection{Another to number but do not include in the TOC}
\section{More}
\subsection{A sub-section to number and include in TOC}

\end{document}


• This seems to work in the example. In my actual document this did not work but I think it's due to the way the cls was built. I found a work around. After the section tag I set \settocdepth{section} – agf1997 Nov 14 '19 at 17:01
• @agf1997 Could well be. ;-) I wrote an answer for the document class book because this is what the MWE uses. ;-) – Schrödinger's cat Nov 14 '19 at 17:04
• No doubt .... that's my fault. The class I'm using is based on book but obviously too complicated and specific to make sense to post here. I'll accept your answer since it answered by MWE question. Thanks for the help. It helped me get to the solution that worked for my specific problem. – agf1997 Nov 14 '19 at 21:46