3

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!

  • 1
    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
4

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}

enter image description here

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

2

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:

enter image description here


With a standard class you can use

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

enter image description here

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}

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.