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:

• lof: list of figures
• lot: list of tables

##### 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}

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:

%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
\listoffigures
\listoftables

%report and book
\tableofcontents
\clearpage %\cleardoublepage %for openright
\listoffigures
\clearpage %\cleardoublepage %for openright
\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.

In large documents, you may end up with a pretty long list of figures or tables. In this post, I will show how to nicely structure these lists by adding subtitles. The whole thing turned out to be more tricky than I first thought, but more on that later. The my examples, I will show how to organize the list of figures by chapters. However, the code can be adapted and extended with little effort, including doing the same for the list of tables, organizing the lists by different levels (part, section) for the various documentclasses, the actual subtitle format (with/without name, page number), etc.

The main idea is to add a line to the list of figures whenever a new chapter is created. That’s relatively straight forward, we extend the chapter command by defining a custom command.

\newcommand{\newchapter}[1]{%
\chapter{#1}
Chapter \thechapter: #1 \vspace{10pt}
}
}

The lines highlighted add a full entry to the list of figures. In order to omit the page number, use addtocontents as follows instead.

\addtocontents{lof}{\contentsline{chapter}{%
Chapter \thechapter \vspace{10pt}}{}
}

This is all great and easy. The problem starts, however, when individual chapters have no figures. Then, the subtitle will still be printed, however, that there is no content. This is not exactly what we want. Therefore, we add a condition on when to print the subtitle and when not. The etoolbox package comes in handy here, it provides “if-then-else-like” statements. Here is the documentation. Briefly, whenever a new chapter starts, we set the parameter newchap to true. The subtitle is printed along with the first caption added to the list of figures. Therefore, if a chapter has no figure, the subtitle will not show up in the list.

First, we define the boolean parameter newchap:

\providebool{newchap}

Next, we define an alternative chapter command newchapter. This time, however, instead of directly adding the subtitle to the list, we only set the boolean parameter to true:

\newcommand{\newchapter}[1]{%
\chapter{#1}
\global\setbool{newchap}{true}
}

And finally, we redefine the caption command. The additional definition of shortcaption is necessary to support the optional caption argument, the alternative short caption for the list of figures.

\let\oldcaption\caption
\renewcommand{\caption}[2][\shortcaption]{%
\def\shortcaption{#2}
\ifbool{newchap}{%
Chapter \thechapter \vspace{10pt}
}{}}}{}
\global\boolfalse{newchap}
\oldcaption[#1]{#2}
}

If you never use the optional argument of the chapter command (chapter[alternative toc name]{real chapter name}) throughout your document, this is basically it, we are done.

In case you use the optional augment, however, we are not quite done yet, since we redefined chapter and by doing so omitted some of the functionality. We can fix this issue by redefining chapter in a different way, similarly to what we did for caption which brings additional advantages. On one hand, the code becomes more consistent and on the other hand, you won’t have to change chapter to newchapter throughout your document, since we just redefine the command rather than replace it. And here is the code:

\makeatletter
\newcommand{\saved@chapter}{}
\let\saved@chapter\chapter
\renewcommand{\chapter}{%
\@ifstar {\saved@chapter*}{\@dblarg\my@chapter}%
}
\newcommand*{\my@chapter}[2][]{%
\saved@chapter[#1]{#2}%
\global\setbool{newchap}{true}
}
\makeatother

I got this piece of code from this google group.

And here is what the final result looks like. Pretty cool, huh :-).

List of figures with subtitles

The whole story only makes sense and works with numbered chapters, (i.e. when using the starred version: \chapter*{} you may run into problems or get undesired results, but you would have to try).

I am pretty sure there is an alternative, maybe simpler way to do the same thing. Maybe the tocloft package has a solution. Feel free to drop a comment and let me know about it. Thanks.

## 10 ways to customize toc/lof/lot

I put together this list of 10 ways to customize the Table of Contents, List of Figures and List of Tables. Some of them are pretty common, some may be new to you. Hope you enjoy the list…

Some pieces of code below require the tocloft package which provides extensive customization functionality for table of contents, list of figures and list of tables. It will be indicated wherever the tocloft or any other package needs to be loaded in the preamble.

Note: I will use the abbreviations toc for table-of-contents, lof for list-of-figures and lot for list-of-tables in the article below.

Change the heading can be done without loading any specific package. Obviously, the name has to be changed before creating the list.

\renewcommand\contentsname{}
\tableofcontents
\renewcommand\listfigurename{}
\listoffigures
\renewcommand\listtablename{}
\listoftables

2. Add “Page” above page numbers

Several people asked me how to place the word “Page” on top of the page numbers in toc/lof/lot. Here is how you do it:

\tableofcontents
\chapter{...}

"Page" above page numbers

It works the same way with lof and lot. The code was taken from here.

3. Change depth of entries

You can change the depth, i.e. how many levels shall be printed using the respective counter:

\setcounter{tocdepth}{1}
\tableofcontents

0: chapter (not available for \documentclass{article),
1: section,
2: subsection, etc.
The default depth is 3, subsubsection.
Similarly, including subfigures and subtables can be achieved using:

\setcounter{lofdepth}{2}
\setcounter{lotdepth}{2}

4. Roman page numbers for toc/lof/lot

To get a different page number style for toc/lof/lot, use:

\pagenumbering{}

and change it back to arabic before the first chapter starts.

Available styles are arabic, roman, Roman, alph and Alph.

Complete code example:

...
\pagenumbering{roman}
\tableofcontents
\listoffigures
\listoftables
\clearpage
\pagenumbering{arabic}
\chapter{...}
...

Loading the hyperref package will let you navigate from toc/lof/lot entries directly to the respective content:

\usepackage{hyperref}

If you only want the page number to be clickable, you’ll need to load the package with the following option:

\usepackage[linktocpage=true]{hyperref}

6. Adding the lists to toc

Adding entries to toc/lof/lot can be done manually with a single command. Usually, to be sure the page number is correct, it’s advisable to add entries directly before or after the actual content to list. And here is how:

\addcontentsline{}{}{}

The file line(s) shall be added (toc, lof or lot), the type of the entry (chapter, figure, etc.) and the entry text itself.

To add the three lists to the toc use:

\tableofcontents
\listoffigures
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}

7. Changing the font of entries

To change the way the actual entries look, you can make use of a command provided by the tocloft package. The command will affect the number as well as the text. However, it will not change the page number and the separator (if there are any). The nice thing here is that since it’s placed just in front of the sequence number, you can also use it to add words such as “Chapter 1: Biology … Here are a few examples for illustration:

\usepackage{tocloft}
\renewcommand{\cftchapfont}{\scshape}
\renewcommand{\cftsecfont}{\bfseries}
\renewcommand{\cftfigfont}{Figure }
\renewcommand{\cfttabfont}{Table }

Try it and make sure you don’t forget the space behind Figure_ and Table_, otherwise it will be glued to the number.

8. Creating you own list of …

Again, the tocloft package has to be loaded. First, define a new list environment as well as the item which are later being listed. In this case, we are defining lemmas, but it could also be proofs, equations, a special list of figures, footnotes, anything. The last line of the lemma command defines how lemmas should be numbered, here “chapter.lemma”.

\usepackage{tocloft}
...
\newcommand{\listlemmaname}{List of Lemmas}
\newlistof{lemma}{lem}{\listlemmaname}
\newcommand{\lemma}[1]{%
\refstepcounter{lemma}
\par\noindent\textbf{Lemma \thelemma. #1}
{\protect\numberline{\thechapter.\thelemma}#1}\par
}
...
\listoflemma
...
\lemma{My first lemma}
\label{lem:lemma1}

You can find a complete code example here.

9. Alternative text in toc/lof/lot for headings and captions

In case your caption is too long for the lof/lot, you can give it an alternative text. Similarly, the headings can be given an alternative name in the toc:

\caption[]{}
\chapter[]{}

10. Chapter specific tocs with minitoc

Finally, minitoc produces beautiful tocs at the beginning of every chapter (or any other heading) and therefore, I will dedicate this 10th and last entry to that package:

\usepackage{minitoc}
...
\dominitoc
\tableofcontents
...
\chapter{...}
\minitoc

A minitoc example

Here is an earlier post I wrote about the package as well as the complete documentation.

Wow, that’s the longest post I ever wrote. Hope you’ve enjoyed my list, have fun customizing :-).

## Glossary in Latex

A glossary is a nice thing to have in a report and usually very helpful. As you probably can imaging, it is very easy to create in Latex. Nevertheless, there are a few things to be done, especially generating the glossary-files.

First you have to tell Latex to use the glossary package and to create the glo-file containing all the glossar-entries in your document:

\usepackage{glossary}
\makeglossary

Next you have to add glossary entries to your document. They are of the following form:

\glossary{name={entry name}, description={entry description}}

Note: Usually, the glossary-entry should be added to keywords where they first appear.

A glossary-entry produces by default the following format:

"entry name" "entry description (on multiple lines if necessary)", "page number"

And finally you have to tell Latex where to place you glossary inside the document which is done by the following command at the location you want to produce the glossary:

\printglossary

Optinally, you can reference to the glossary in the index (toc-file) by adding the following command after \printglossary":

\addcontentsline{toc}{chapter}{Glossary}

What you do first is generate your PDF once. An ist-file as well as a glossary file (*.glo) are generated. The glossary-file contains all the glossary entries found in the document in plain text. Next you type the following command in the command-line:

makeindex document.glo -s document.ist -t document.glg -o document.gls

generating the two files with the extensions *.gls and *.glg. If entries are ignored or rejected, which can be seen either in the glg-file or directly in the output of the makeindex-command, you have to check your glossary entries. The important of the two files is the *.gls-file, as it is used by Latex for the actual glossary. You now need to re-generate the PDF and if everything works fine, your glossary should appear where you wanted it.

Good luck:-)