0

I have the following document:

\documentclass[11pt, a4paper, headsepline]{scrbook} 

\begin{document}

 \tableofcontents

 \chapter{Chapter one}
 \section{Section one.one}
 \subsection{Subsection one.one.one}
 \subsection{Subsection one.one.two}
 \section{Section one.two}
 \subsection{Subsection one.two.one}
 \subsection{Subsection one.two.two}
 \section{Section one.three}
 \subsection{Subsection one.one.one}
 \subsection{Subsection one.one.two}

\end{document}

But I want the following toc:

1 Chapter one
1.1 Section one.one
1.1.1 Subsection one.one.one
1.1.2 Subsection one.one.two
1.2 Section one.two <<<--- here subsections are missing
1.3 Section one.three
1.3.1 Subsection one.one.one
1.3.2 Subsection one.one.two

Excluding some subsections via \addtocontents{toc}{\setcounter{tocdepth}{1}} didn't work or maybe I implemented it wrong. Any hints?

  • So you only want to exclude stuff from the toc? – Skillmon Jul 19 '17 at 18:15
  • 1
    Correct, however, the answer below did work :D – Kay Jul 19 '17 at 18:23
2

You need to protect the \setcounter:

\documentclass[11pt, a4paper, headsepline]{scrbook}

\begin{document}

 \tableofcontents

 \chapter{Chapter one}
 \section{Section one.one}
 \subsection{Subsection one.one.one}
 \subsection{Subsection one.one.two}
 \section{Section one.two}
 \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
 \subsection{Subsection one.two.one}
 \subsection{Subsection one.two.two}
 \addtocontents{toc}{\protect\setcounter{tocdepth}{3}}
 \section{Section one.three}
 \subsection{Subsection one.one.one}
 \subsection{Subsection one.one.two}

\end{document}

 You can also use the tocvsec2 package https://ctan.org/pkg/tocvsec2

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.