Display only LOWER levels of chapters/sections in TOC using \setcounter{tocdepth}?

I have a question about the table of contents: I know that, e.g., \setcounter{tocdepth}{2} can be used if I want to, only display parts, chapters and sections in the table of contents and supress subsections and below.

My question, however, is if the opposite is possible - for example ONLY displaying sections and lower levels and not showing parts and chapters. Using \section* or equivalent is not an option in this case.

Thanks!

• Welcome to TeX.SE! What is wrong with the starred command \chapter*, \part*? Or do you need the numbering? (Though numbered but not in the TOC seems rather strange...) – campa May 4 '18 at 9:34

It will depend on the class, but with book you can e.g. do

\documentclass{book}
\makeatletter
\renewcommand*\l@part[2]{}
\renewcommand*\l@chapter[2]{}
\makeatother
\begin{document}
\tableofcontents

\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}
\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}

\end{document}


\renewcommand*\l@section[2]{} will also suppress the sections.

With a KOMA-Script class you can change the style of ToC entries to gobble using

\RedeclareSectionCommands[tocstyle=gobble]{part,chapter}


or

\DeclareTOCStyleEntry{gobble}{part}
\DeclareTOCStyleEntry{gobble}{chapter}


Example:

\documentclass{scrbook}
\RedeclareSectionCommands[tocstyle=gobble]{part,chapter}
\begin{document}
\tableofcontents
\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}
\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}
\end{document}


Result:

With a standard class you can use

\usepackage{tocbasic}
\DeclareTOCStyleEntry[level=-1]{gobble}{part}
\DeclareTOCStyleEntry[level=0]{gobble}{chapter}


Code:

\documentclass{book}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[level=-1]{gobble}{part}
\DeclareTOCStyleEntry[level=0]{gobble}{chapter}
\begin{document}
\tableofcontents
\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}
\part{a part}
\chapter{a chapter}
\section{a section}
\subsection{a subsection}
\end{document}