5

Is it possible to omit a single specific subsection from the table of contents, while keeping it numbered as usual within the main body, and keeping other subsections listed?

(I am using the amsart class.)

1
  • 3
    Why would you want to do that? Just curious...
    – vonbrand
    Mar 2 '13 at 1:17
4

The following code provides the an \addsubsection macro that works similar to \subsection (starred version, optional argument) that uses the \qrr@gobblenexttocentry macro to suppress the content that gets written to the .toc file.

When the hyperref package is used this line consists of five parameters, hence the \ifcsname check.

This won’t work if between the to-be-hidden subsection and its predecessor is not a single character. (But why would one do this?)

Reference

Code

\documentclass{amsart}

%\usepackage{hyperref}% works with or without hyperref

\makeatletter
\ifcsname phantomsection\endcsname
    \newcommand*{\qrr@gobblenexttocentry}[5]{}
\else
    \newcommand*{\qrr@gobblenexttocentry}[4]{}
\fi
\newcommand*{\addsubsection}{%
    \addtocontents{toc}{\protect\qrr@gobblenexttocentry}%
    \subsection}
\makeatother

\usepackage{lipsum}
\begin{document}
\tableofcontents
\section{section name}
\lipsum[1]
\subsection{I'm here.}
\lipsum[1]
\addsubsection{I'm gone.}
\lipsum[1]
\subsection{I'm there.}
\lipsum[1]
\end{document}

Output

enter image description here

2

In the following code, whatever is put between \ignorethis...\endignorethis is ignored, and \TOCstop with \TOCstart simply write these two commands into the .toc file.

\documentclass{article}

\protected\def\ignorethis#1\endignorethis{}
\let\endignorethis\relax
\def\TOCstop{\addtocontents{toc}{\ignorethis}}
\def\TOCstart{\addtocontents{toc}{\endignorethis}}

\begin{document}

\tableofcontents

\section{FOO}
\subsection{BAR}
\TOCstop
\subsection{BAZ}
\TOCstart
\subsection{BAR}

\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.