texblog

LaTeX table of contents, list of figures/tables and some customizations

I wrote a somewhat short post on list of figures and list of tables a few years ago. Nevertheless, it gets quite a bit of traffic, possibly due to the large number of comments. For that reason, I decided to put together another, more informative post on the same topic that includes table of contents.

I use the following common abbreviations throughout the post:

 

Topics

 

Creating content lists, the basic commands

Creating content lists in LaTeX documents is straight forward. Typing these three commands is sufficient to produce a toc, lof, and lot. To produce the lists, the document has to be typeset twice. The first iteration collects all headings and captions and writes them to meta files (*.toc, *.lof, *.lot). The second iteration prints the lists, based on the content of the meta files.

\tableofcontents
\listoffigures
\listoftables

\documentclass[11pt]{article}

\begin{document}

\tableofcontents
\listoffigures
\listoftables

\clearpage

\section{Dummy section 1}
\begin{figure}[ht]
\begin{center}

\caption{Dummy figure 1}
\label{fig:dum1}
\end{center}
\end{figure}

\begin{figure}[ht]
\begin{center}

\caption{Dummy figure 2}
\label{fig:dum2}
\end{center}
\end{figure}

\begin{table}[ht]
\caption{Dummy table 1}
\begin{center}
\begin{tabular}{|c|c|}

\end{tabular}
\end{center}
\label{tab:dum1}
\end{table}

\section{Dummy section 2}

\end{document}

Depending on the document-class employed, page-breaks are added between toc, lof, and lot. Article produces lists without space between them. Report and book insert \clearpage or \cleardoublepage, depending on whether twoside and openright options are set (default for book), to start each list on a blank page. See here for more details on document-class options.

 

Controlling the depth of content added to toc

Depending on the size of your document (length of chapters, sections, etc.), you might want to increase or decrease the level of headings added to toc. To control the depth of content added to toc the counter tocdepth is modified in the preamble as follows:

\setcounter{tocdepth}{level}
%level -1: part, 0: chapter, 1: section, etc.

In the following example all headings are added to toc (level: 5):

\documentclass[11pt]{report}

\setcounter{tocdepth}{5} %shows all levels incl. paragraph
\begin{document}

\tableofcontents

\chapter{Dummy chapter}
\section{Dummy section}
\subsection{Dummy subsection}
\subsubsection{Dummy subsubsection}
\paragraph{Dummy paragraph}

\end{document}

 

Adding lof/lot to toc

Lists of figures and tables are not automatically added to the table of contents. I will introduce two different approaches here, an automatic and a manual approach.

Automatic approach:

Loading tocbibind (package documentation) adds entries for lof and lot to toc. In addition, the package adds bibliographies and table of contents itself, by default. This might not always be desirable. Therefore, specific entries can be removed from toc by loading the package with corresponding options, such as: nottoc, notbib, notlof:

%preamble
\usepackage[nottoc]{tocbibind}

%content
\tableofcontents
\listoffigures
\listoftables

Manual approach:

Lof and lot can be added manually through \addcontentsline. The command takes three arguments: the file (e.g. toc), the level (e.g. chapter), and the text to be added.

%article
\tableofcontents
\addcontentsline{toc}{section}{\listfigurename}
\listoffigures
\addcontentsline{toc}{section}{\listtablename}
\listoftables

%report and book
\tableofcontents
\clearpage %\cleardoublepage %for openright
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures
\clearpage %\cleardoublepage %for openright
\addcontentsline{toc}{chapter}{\listtablename}
\listoftables
\clearpage %\cleardoublepage %for openright

\listfigurename and \listtablename produce the list headings. This way, toc entries are automatically updated, should the headings be changed for some reason. Adding the lists to toc before the actual command as well as them makes sure the page numbers are set correctly. The document-class option openright (requires twoside in report) always starts chapters on odd pages, which is when \cleardoublepage comes in handy. It adds either one or two page-breaks depending on whether the content ends on an even or odd page.

 

Short captions for lof/lot

Some figures and tables have long captions. It might not always be preferable to reproduce the whole caption in lof/lot. The caption command provides a convenient way to produce a shorter figure/table description in the lof/lot by using its optional argument, without change to the actual figure/table caption.

\caption[short lof/lot caption]{long caption ...}

\documentclass[11pt]{article}
\usepackage{blindtext}
\begin{document}

\tableofcontents
\listoffigures

\section{Dummy section 1}
\begin{figure}[ht]
\begin{center}
\rule{0.5\linewidth}{0.35\linewidth}
\caption[Long caption figure]{\blindtext}
\label{fig:dum1}
\end{center}
\end{figure}

\end{document}

The same works with headings and table of contents. The \chapter and \section commands also take an optional argument which, when used, produce an alternative chapter/section name in toc.

\chapter[Short chapter name]{Long chapter name ...}

 

Linking toc/lof/lot with content using hyperref

Loading hyperref (package documentation) is generally sufficient to link list entries with document content. With some exceptions, the hyperref package usually has to be loaded last. For a better visualisation of links, it is a good idea to change the link font color, e.g. to blue:

\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

 

Further customizations

This earlier post describes 10 ways to customize toc/lof/lot, from basic to more advanced topics.

 

The tocloft package

The tocloft package provides means of controlling the typographic design of table of contents, list of figures and list of tables (copied from its documentation). Introducing the package would go beyond the scope of this article. However, I am happy to help should you have any specific question. Just drop me a comment below.

Exit mobile version