[Tex/LaTex] LaTeX – Different section names in TOC from body

numberingsections-paragraphstable of contents

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!

Best Answer

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.

Related Question