24

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!

  • 2
    \section[short]{long} – David Carlisle May 2 '14 at 15:08
  • 3
    You should use the optional argument: \section[<ToC>]{<Text>}. – Werner May 2 '14 at 15:08
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Heiko Oberdiek May 2 '14 at 15:30
27

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.

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.