4

I recently solved a problem for adding footnotes in a chapter title by changing \chapter{Title\footnote{text}} to \chapter[Title]{Title\footnote{text}}.

However, I don't understand why this works. What is the difference between the two, and what is the purpose of [ ] in this setting? It seems like I can write anything in \section[ANYTHING!]{Section Title} without changing the output.

  • 1
    The stuff in square brackets goes into the table of contents. You can also use the same trick for captions of figures: If you write\caption[one]{two}, then "one" goes into the list of figures, while "two" will be the actual caption. – Mark May 12 '16 at 15:50
5

The [Short Title] content is meant for the ToC and page headers only, to provide a shorter title, whereas the \chapter{Longer Title} is displayed on the page body. As long as you don't use \tableofcontents you won't notice ANYTHING at all (and not using page headers as well)

If the [...] version is omitted, ToC entry and chapter header entry are the same (by design), that's why it's used as an optional argument.

The design of of this \cmd[Short title]{Long title} is 'general' in the sense that it use usable for the \part, \chapter, \section etc, and for \caption (or \captionof).

Please note, that the memoir class provides a second optional argument, i.e. \chapter[ToC title][header title]{body page title}, i.e. the 2nd optional argument is used then for the title which should appear in the page header.

Here's an example:

\documentclass{book}


\usepackage{blindtext}

\begin{document}

\tableofcontents

\chapter[ANYTHING]{This is used in body}

\blindtext[10] 
\chapter[\protect\footnote{This is a footnote}]{Other chapter}

\blindtext[10] 


\end{document}

The example shows that ANYTHING used in the optional argument will be display both in ToC as well as in the page header, as well as the 'stupid' \footnote superscript.

In order to use fragile commands (such as \footnote etc. one has to \protect them or \robustify them (use etoolbox package for this, for example)

  • Thank you. Will refrain from using foul language in the brackets then:) – user3218615 May 12 '16 at 15:51
  • the amsbook document class also is a bit different from book: the optional argument is used only in the running head; the full text of the heading is used in the toc. (there is an easy workaround for modifying the toc text if necessary.) – barbara beeton May 12 '16 at 17:15
4

The optional argument to sectional commands are dedicated for ToC-related entries. And, entries to the ToC are treated differently than that of the regular title within the document body. More specifically, ToC entries are written to the .toc file, which may incur expansion problems (typical of what you observed when you used \footnote in the section title). So yes, you can use \section[<anything>]{<title>} where <title> now contains all kinds of weird stuff, but you'll notice <anything> once you issue \tableofcontents.

Here's an example:

enter image description here

\documentclass{article}

\usepackage{xcolor}

\begin{document}

\tableofcontents

\section{A section}
\section[Second section]{Another section}
\section[This section]{This section\footnote{A section footnote}}
\section[Yet another \protect\textcolor{blue}{section}]{Yet another \textcolor{red}{section}}

\end{document}

Robust commands tend to remain unexpanded when written to the .toc, but not all commands are defined this way. In such instanced one needs to \protect the command from expansion or define it to be robust.

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.