1

I'm working on a document where I want to exclude several (sub)sections on different toc-depths from being listed inside the TOC.

Example:

Chapter 1
Section 1.1
Subsection 1.1.1 << remove
Subsection 1.1.2 << remove

Section 1.2
Section 1.3 << remove
Section 1.4

Excluding these sections via tocdepth isn't possible for me. So my idea was to have modified \chapter*, \section*, \subsection* ... commands that generate the headings (including the formatting and numbering) as usual but don't list the entries inside the TOC.

Is there a way to get this to work?

Thx & Bye, Holger

  • 1
    You can change tocdepth locally with tocvsec2: ctan.org/pkg/tocvsec2 – Ulrike Fischer Oct 16 '17 at 16:40
  • 3
    Short answer (because of missing MWE): If you use an empty string for the ToC-entry it automatically will not be added. You can do this using the optional argument of the (sub)section command. – Schweinebacke Oct 16 '17 at 16:48
2

You can use the extended optional argument of the sectioning commands. KOMA-Script will automatically omit empty ToC entries. To switch on the parsing for the extended optional argument, you have to use one of the following options:

  • headings=optiontotocandhead: Use the not extended optional argument for both the ToC and the running head
  • headings=optiontotoc: Use the not extended optional argument for the ToC only but the mandatory argument for the running head
  • headings=optiontohead: Use the not extended optional argument for the running head, but the mandatory argument for the ToC

So you can either use:

\documentclass[
  headings=optiontotocandhead% switch on extended optional argument parsing
                             % for sectioning commands
]{scrbook}

\setcounter{tocdepth}{\subsectiontocdepth}% generally show part, chapter,
                                          % section and subsection in the ToC

\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1.1}
\lipsum[2]
\subsection[tocentry={}]{Subsection 1.1.1}% no ToC entry
\lipsum[3]
\subsection[tocentry={}]{Subsection 1.1.2}% no ToC entry
\lipsum[4]
\section{Section 1.2}
\lipsum[5]
\section[tocentry={}]{Section 1.3}% no ToC entry
\lipsum[6]
\section{Section 1.4}
\lipsum[7]
\subsection{Subsection 1.5}
\lipsum[8]
\end{document}

or

\documentclass[
  headings=optiontotoc% switch on extended optional argument parsing
                      % for sectioning commands and restrict it to the ToC
]{scrbook}

\setcounter{tocdepth}{\subsectiontocdepth}% generally show part, chapter,
                                          % section and subsection in the ToC

\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1.1}
\lipsum[2]
\subsection[]{Subsection 1.1.1}% no ToC entry
\lipsum[3]
\subsection[]{Subsection 1.1.2}% no ToC entry
\lipsum[4]
\section{Section 1.2}
\lipsum[5]
\section[]{Section 1.3}% no ToC entry
\lipsum[6]
\section{Section 1.4}
\lipsum[7]
\subsection{Subsection 1.5}
\lipsum[8]
\end{document}

to get

resulting ToC

0

Don't do it.


Is there a way to get this to work?

No. As described in the answer of Schweinebacke you can get a table of contents with discontinuous numbering.

But it will not work, because your readers just will just assume that your toc is buggy.

This again is an idea without any consideration of the readers expectations. Don't do it. Readers can not come back and ask you.

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.