25.1.2 \addcontentsline

Synopsis:

\addcontentsline{ext}{unit}{text}

Add an entry to the auxiliary file with extension ext.

The following will result in an ‘Appendices’ line in the table of contents.

\addcontentsline{toc}{section}{\protect\textbf{Appendices}}

It will appear at the same indentation level as the sections, will be in boldface, and will be assigned the page number associated with the point where the command appears in the input file.

The \addcontentsline command writes information to the file root-name.ext, where root-name is the file name of the root file (see Splitting the input). It writes that information as the text of the command \contentsline{unit}{text}{num}, where num is the current value of counter unit (see \contentsline). The most common case is the table of contents and there num is the page number of the first page of unit.

This command is invoked by the sectioning commands \chapter, etc. (see Sectioning), and also by \caption inside a float environment (see Floats). But it is also directly used by authors. For example, an author writing a book whose style is to have an unnumbered preface may use the starred \chapter*. But that command leaves out table of contents information, which can be entered manually, as here.

\chapter*{Preface}
\addcontentsline{toc}{chapter}{\protect\numberline{}Preface}

In the root-name.toc file LaTeX will put the line \contentsline {chapter}{\numberline {}Preface}{3}; note that the page number ‘3’ is automatically generated by the system, not entered manually.

All of the arguments for \addcontentsline are required.

ext

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

unit

A string that depends on the value of the ext argument, typically one of:

toc

For the table of contents, this is the name of a sectional unit: part, chapter, section, subsection, etc.

lof

For the list of figures: figure.

lot

For the list of tables: table.

text

The text of the entry. You must \protect any fragile commands (see \protect) used in it.

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

If you use a unit that LaTeX does not recognize, as with the typo here

\addcontentsline{toc}{setcion}{\protect\textbf{Appendices}}

then you don’t get an error but the formatting in the table of contents will not make sense.


Unofficial LaTeX2e reference manual