32

Sorry if this question already appears elsewhere, I couldn't find it.

Is there a way to label a section in the text but give it a different name in the table of contents?

I have very long section titles but would like to give them nicknames in the TOC. I tried using \section*{A} then \addcontentsline{toc}{section}{B} but this removes the numbering of the section from the body of the text.

I'm very new to LaTeX so sorry if this is an annoying question!

Heiko Oberdiek
  • 271,626
Gemma
  • 345

2 Answers2

37

Most document classes offer the user the option of specifying a different ToC-related entry for the sectional unit that what is displayed in the actual document body through an optional argument:

\part[<ToC-part>]{<Body-part>}
\chapter[<ToC-chapter>]{<Body-chapter>}
\section[<ToC-section>]{<Body-section>}
\subsection[<ToC-subsection>]{<Body-subsection>}
\subsubsection[<ToC-subsubsection>]{<Body-subsubsection>}
...

This allows one to effectively create a completely different ToC than what is contained within the actual document. However, it provides many advantages, including:

  • Abbreviating the ToC-related content that would otherwise look awkward or not make sense;

  • Remove notation from a sectional unit that is not defined when the reader views the ToC;

  • Include "bizarre" things as part of the heading;

  • ...

enter image description here

\documentclass{report}
\usepackage{graphicx}
\begin{document}

\tableofcontents

\chapter[Interesting]{A very long chapter title that is not necessary in the ToC}

\section[Some math]{The graph $G\langle m,n;k\rangle$}

\subsection[Pictures]{The image \includegraphics[height=\baselineskip]{example-image}}

\end{document}

Common usages (apart from the above ones) stems from the fact that sectional units' mandatory argument ends up moving. That is, they find their way into the text where you put it, but also in the ToC. And, moving arguments is sometimes fragile, so care has to be taken with the content they may contain. The optional argument provides an easy-way-out where one can remove the "unwanted" content and specify your own.

Werner
  • 603,163
2

As a comment-like extension to the answer by @Werner:

The documentclass amsbook is one of those classes that do not offer the optional argument for a TOC-related naming of chapters, sections, subsection an alike. However, by the documentation, page 14, there are alternative commands \except{toc}{} and \for{toc}{} to control what goes not into the table of contents and only there, respectively.

Replacing \chapter[name for TOC]{name for main text} with

\documentclass{amsbook}

\begin{document} \chapter{\for{toc}{name for TOC}\except{toc}{name for main text}}

then gives the same result.

This sometimes even saves repetition of the common part as in

\chapter{name common to TOC and main text 
\except{toc}{with additional details only in main text}}