Table of contents etc.

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 the following line to test.toc.

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

The section or subsection is the sectioning unit. The hook \numberline lets you to change how the information appears in the table of contents. Its unique argument, 1 or 1.1, is the sectioning unit number, whereas the remainder of the second argument of \contentsline, First section or First subsection, is the title. Finally, the third argument, 2, is the page number on which the sectioning units start.

One consequence of this auxiliary file storage strategy is that to get the contents page correct you must run LaTeX twice, once to store the information and once to get it. In particular, the first time that you run LaTeX on a new document, the table of contents page will be empty except for its ‘Contents’ header. Just run it again.

The commands \listoffigures and \listoftables produce a list of figures and a list of tables. They work the same way as the contents commands; for instance, these work with information stored in .lof and .lot files.

To change the header for the table of contents page do something like the first line here.

\renewcommand{\contentsname}{Table of contents}
\renewcommand{\listfigurename}{Plots}
\renewcommand{\listtablename}{Tables}

Similarly, the other two lines will do the other two. Internationalization packages such as babel or polyglossia will change the headers depending on the chosen base language.

CTAN has many packages for the table of contents and lists of figures and tables. One convenient one for adjusting some aspects of the default, such as spacing, is tocloft. And, tocbibbind will automatically add the bibliography, index, etc. to the table of contents.

© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/Table-of-contents-etc_002e.html