W3cubDocs

/LaTeX

\addtocontents

Synopsis:

\addtocontents{ext}{text}

Add text, which may be text or formatting commands, directly to the auxiliary file with extension ext. This is most commonly used for the table of contents so that is the discussion here, but this also applies to the list of figures and list of tables.

This will put some vertical space in the table of contents after the ‘Contents’ header.

\tableofcontents\newpage
\addtocontents{toc}{\protect\vspace*{3ex}}

The \addtocontents command has two arguments. Both are required.

ext

Typically one of: toc for the table of contents, lof for the list of figures, or lot for the list of tables. The extension of the file holding the information.

text

The text, and possibly commands, to be written.

The sectioning commands such as \chapter use the \addcontentsline command to store information. This command creates lines in the .toc auxiliary file containing the \contentsline command (see \addcontentsline). In contrast, the command \addtocontents puts material directly in that file.

The \addtocontents command has an interaction with \include (see \include & \includeonly). If you use them at the same level, as with \addtocontents{...}{...}\include{...} then lines in the table of contents can come out in the wrong order. The solution is to move \addtocontents into the file being included.

© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/_005caddtocontents.html