25.1 Table of contents, list of figures, list of tables

Synopsis, one of:


Produce a table of contents, or list of figures, or list of tables. Put the command in the input file where you want the table or list to go. You do not type the entries; for example, typically the table of contents entries are automatically generated from the sectioning commands \chapter, etc.

This example illustrates the first command, \tableofcontents. LaTeX will produce a table of contents on the book’s first page.

% \setcounter{tocdepth}{1}

Uncommenting the second line would cause that table to contain chapter and section listings but not subsection listings, because the \section command has level 1. See Sectioning, for level numbers of the sectioning units. For more on the tocdepth see Sectioning/tocdepth.

Another example of the use of \tableofcontents is in Larger book template.

If you want a page break after the table of contents, write a \newpage command after the \tableofcontents command, as above.

To make the table of contents, LaTeX stores the information in an auxiliary file named root-file.toc (see Splitting the input). For example, this LaTeX file test.tex

\section{First section}
\subsection{First subsection}

writes these lines to test.toc.

\contentsline {section}{\numberline {1}First section}{2}
\contentsline {subsection}{\numberline {1.1}First subsection}{2}

Each line contains a single command, \contentsline (see \contentsline). The first argument, the section or subsection, is the sectioning unit. The second argument has two components. The hook \numberline determines how the sectioning number, 1 or 1.1, appears in the table of contents (see \numberline). The remainder of the second argument of \contentsline, ‘First section’ or ‘First subsection’, is the sectioning title text. Finally, the third argument, ‘2’, is the page number on which this sectioning unit starts.

To typeset these lines, the document class provides \l@section-unit commands such as \l@section{text}{pagenumber} and \l@subsection{text}{pagenumber}. These commands often use the \@dottedtocline command (see \@dottedtocline).

A consequence of LaTeX’s strategy of using auxiliary files is that to get the correct information in the document you must run LaTeX twice, once to store the information and the second time to retrieve it. In the ordinary course of writing a document authors run LaTeX a number of times, but you may notice that the first time that you compile a new document, the table of contents page will be empty except for its ‘Contents’ header. Just run LaTeX again.

The commands \listoffigures and \listoftables produce a list of figures and a list of tables. Their information is stored in files with extension .lof and .lot. They work the same way as \tableofcontents but the latter is more common, so we use it for most examples.

You can manually add material to the table of contents, the list of figures, and the list of tables. For instance, add a line about a section to the table of contents with \addcontentsline{toc}{section}{text}. (see \addcontentsline). Add arbitrary material, that is, non-line material, with \addtocontents, as with the command \addtocontents{lof}{\protect\vspace{2ex}}, which adds vertical space to the list of figures (see \addtocontents).

Lines in the table of contents, the list of figures, and the list of tables, have four parts. First is an indent. Next is a box into which sectioning numbers are placed, and then the third box holds the title text, such as ‘First section’. Finally there is a box up against the right margin, inside of which LaTeX puts the page number box. For the indent and the width of the number box, see \@dottedtocline. The right margin box has width \@tocrmarg and the page number is flush right in that space, inside a box of width \@pnumwidth. By default \@tocrmarg is 2.55em and \@pnumwidth is 1.55em. Change these as with \renewcommand{\@tocrmarg}{3.5em}.

CTAN has many packages for the table of contents and lists of figures and tables (see CTAN: The Comprehensive TeX Archive Network). The package tocloft is convenient for adjusting some aspects of the default such as spacing. And, tocbibbind will automatically add the bibliography, index, etc. to the table of contents.

To change the header for the table of contents page, do something like these commands before you call \tableofcontents, etc.

\renewcommand{\contentsname}{Table of Contents}

Internationalization packages such as babel or polyglossia will change these headers depending on the chosen base language.

Unofficial LaTeX2e reference manual