Next: , Up: Front/back matter   [Contents][Index]

Synopsis, one of:

\tableofcontents
\listoffigures
\listoftables

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.

\documentclass{book}
% \setcounter{tocdepth}{1}
\begin{document}
\tableofcontents\newpage
...
\chapter{...}
...
\section{...}
...
\subsection{...}
...
\end{document}

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

\documentclass{article}
\begin{document}
\tableofcontents\newpage
\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.