LaTeX/Tables of Contents and Lists of Figures

< LaTeX

Basic Idea and general commandsEdit

Basic LaTeX provides ways to automatically generate a table of contents (ToC, \tableofcontents) and list of tables/figures (LoT, \listoftables/LoF, \listoffigures) based on the titles or captions. To typeset a table of contents (or LoT/LoF) LaTeX needs helper files; that means every ToC update needs at least two LaTeX runs.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\section{Wombat}
\blindtext
\section{Alpaca}
\blindtext
\begin{figure}
\caption{This is a caption for a non-existing image}
\end{figure}
\section*{Not in ToC}
\end{document}

 


For the article class, those lists are unnumbered sections internally. For the standard report and book class, they are unnumbered chapters; each starting on a new page.

Unnumbered chapters and sections do not appear in the table of contents by default. How to get them to appear.

A table of contents has a depth. By default, three sectioning levels are present in the table of contents. You can specify to which level the ToC should show details. \setcounter{tocdepth}{<number>}

Different titles for the document and the listEdit

The sectioning commands, as well as \caption, provide an optional argument that can take a different title. Usually, this is used to give a shorter caption for the ToC or LoF/LoT.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\section[Alpaca]{Wombat}
\blindtext
\begin{figure}
	\caption[This is the LoF entry]{This is a caption for a non-existing image}
\end{figure}
\end{document}
 
Alternative Titles in LoF and ToC

A table of contents for each chapterEdit

Package etoc can get you a table of contents for single chapters. Following a small example.

 
A local table of contents for a single chapter


\documentclass{book}
\usepackage{etoc}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\etocsettocstyle{\subsection*{This Chapter contains:}}{\noindent\rule{\linewidth}{.4pt}}
\chapter{Extinct Species}
\localtableofcontents
\section{Mammals}
\subsection{Big-eared hopping mouse}
\subsection{Jamaican rice rat}
\subsection{White-footed rabbit-rat}
\section{Butterflies}
\subsection{Nymphalidae}
\subsection{Lycaenidae}
\subsection{Uraniidae}
\end{document}


Customizing the table of contentsEdit

If you want to customize your table of contents, you can choose from a few packages for the standard classes. However, memoir and KOMA-script have built-in methods to customize, using packages breaks functionality of the classes.

Common problemsEdit

Numbers overlap the titlesEdit

LaTeX uses a defined space for entries in the table of contents, which means that long chapter or section numbers sometimes overlap the title. One easy solution is to override this by adding \renewcommand{\numberline}[1]{#1~} to the preamble. Using a dedicated package for ToC customization might be better, though.

 
The chapter number is overlapping the chapter title, a common problem.