The commands \tableofcontents, \listoffigures, and \listoftables gather your heading and caption information and assemble a table of contents, a list of figures, and a list of tables for you. This page covers how that works (auxiliary files and the two-pass run), controlling the depth, adding a starred heading to the contents by hand, and then reshaping the indents, fonts, and dotted leaders with tocloft. The headings themselves are the job of the “Structure, headings & ToC” page; here we focus on generating these lists and customizing them.
The three auto-generated lists
A table of contents is produced simply by placing **\tableofcontents. In the same way, \listoffigures** builds a list of figures from your figure captions and **\listoftables** builds a list of tables from your table captions. You normally place them together in the front matter, just after the title.
All three work the same way. As it processes the document, LaTeX writes the number, title, and page of each heading or caption into an auxiliary file: .toc for the contents, .lof for the figures, and .lot for the tables, each sharing the name of your root file. On the next run it reads that auxiliary file back to typeset the list.
This has an important consequence. On the first run the auxiliary file does not yet exist (or is stale), so the list comes out empty or wrong. To get a correct result you must compile at least twice — the reference manual itself says to “run LaTeX twice, once to store the information and the second time to retrieve it.” Shifting page numbers can force still more runs, and a build tool such as latexmk repeats them automatically until things settle.
The heading titles come from language-aware macros: \contentsname (default “Contents”) for the table of contents, \listfigurename for the list of figures, and \listtablename for the list of tables, each changeable with \renewcommand. In book and report these headings are set as an unnumbered chapter (internally \chapter*), and in article as an unnumbered section. Because they carry no number, the lists themselves do not appear in the contents by default — we add them by hand below.
\documentclass{report}
\begin{document}
\tableofcontents % .toc を使う(2 回処理が必要)
\listoffigures % .lof
\listoftables % .lot
\chapter{序論}
\end{document}How deep the contents go — tocdepth
Which heading levels reach the contents is set by the **tocdepth counter. Its value is a heading level number** (\section is 1, \subsection is 2, a \chapter in book/report is 0, …) naming the deepest level to list. So \setcounter{tocdepth}{1} stops at sections and drops subsections; \setcounter{tocdepth}{2} reaches subsections. The defaults are **3 in article and 2 in book/report**.
Do not confuse it with secnumdepth, which governs numbering. secnumdepth sets how deep headings are numbered; tocdepth sets how deep they are listed in the contents — and the two are independent. You might number down to subsections yet list only down to sections, for instance. The lists of figures and tables have a single level (figure, table), so tocdepth does not affect them.
Adding entries by hand — addcontentsline & addtocontents
A starred heading (\section* or \chapter*) carries no number and no page reference, so it never reaches the contents on its own. When you want an “Introduction,” “Acknowledgements,” a bibliography, or an index to show up there, write a manual line with **\addcontentsline{ext}{unit}{text}**. All three arguments are required.
ext** — the extension of the target auxiliary file:tocfor the contents,loffor the figures,lotfor the tables.unit** — the kind of entry. Fortocit ispart,chapter,section,subsection, etc. (its formatting and indent are used); forlofit isfigure; forlotit istable.text** — the string to list. Prefixing\protect\numberline{}aligns it with numbered entries, and any fragile command in it needs\protect.
Placement matters: \addcontentsline records the page number current when processing reaches that line, so put it immediately after the heading command. The standard pattern for a starred heading is below. The page number is supplied automatically by LaTeX, so you never write it into text.
\section*{はじめに}
\addcontentsline{toc}{section}{はじめに}
\chapter*{謝辞}
\addcontentsline{toc}{chapter}{謝辞}Its companion **\addtocontents{ext}{text} injects material** — spacing or formatting commands — into the auxiliary file rather than a line. It takes two arguments: the target extension ext and the content text to write. To add vertical space in the list of figures, for example, you write the following. Because the .lof is read back on the next run, a fragile command such as \vspace needs \protect. In short: **lines with a page number go through \addcontentsline; spacing and decoration go through \addtocontents**.
\addtocontents{lof}{\protect\vspace{2ex}} % 図目次に縦の空きを差し込む
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}} % ここ以降の目次の深さを変えるReshaping the lists with tocloft
When you want fine control over how the standard lists look, the go-to package is **tocloft** (by Peter Wilson). Load it with \usepackage{tocloft} and set each level’s indent, number width, font, and dotted leader individually, through \renewcommand and dedicated commands. The command names are systematic: they combine a prefix for the list level (toc = \part, chap = \chapter, sec = \section, subsec = \subsection, …, fig for figures, tab for tables) with a role.
For indent and number width, \cftsetindents{entry}{indent}{numwidth} sets both at once: the first argument is the target (section, …), indent is the indent from the left margin, and numwidth is the width reserved for the number. You can also adjust the individual length registers \cftsecindent and \cftsecnumwidth directly with \setlength. When wider numbers start to collide with the title, widen numwidth.
The fonts are separate for the entry and its page number: \renewcommand{\cftsecfont}{...} sets the typeface of a section entry’s title, and \cftsecpagefont sets that of its page number (for chapters, \cftchapfont and \cftchappagefont). The font of a list’s own heading is changed with commands like \cftloftitlefont for the list of figures.
The dotted leader — the row of dots between the title and the page number — is governed by \cftsecleader. Dot density is the length \cftdotsep (default 4.5): smaller packs the dots closer, larger spreads them out. To remove the leader entirely, use \renewcommand{\cftsecleader}{\cftdotfill{\cftnodots}} (\cftnodots is a value large enough to mean “print no dots”). The dot character itself is set by \cftdot (a period by default).
| Command | What it controls | |
|---|---|---|
\cftsetindents | Sets a level’s indent and number width together | {entry}{indent}{numwidth} |
\cftsecfont | Font of a section entry’s title | Redefine via \renewcommand |
\cftsecpagefont | Font of a section entry’s page number | Redefine via \renewcommand |
\cftsecleader | Dotted leader for a section entry | e.g. \cftdotfill{\cftdotsep} |
\cftdotsep | Spacing of leader dots (default 4.5; smaller = denser) | A length (in mu) |
\cftnodots | Value large enough to print no dots | Use it to remove a leader |
Here is an example that makes section titles bold and tightens the dotted leader a little. Put it in the preamble.
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\bfseries} % 節の題を太字に
\renewcommand{\cftsecpagefont}{\bfseries} % ページ番号も太字に
\renewcommand{\cftsecleader}{\bfseries\cftdotfill{\cftdotsep}} % 太字の点線リーダー
\renewcommand{\cftdotsep}{2} % 点をやや密に
\cftsetindents{section}{1.5em}{2.5em} % 字下げと番号幅Putting the lists into the contents
As noted, the headings of \listoffigures, \listoftables (and the bibliography and index) are unnumbered, so they do not appear in the contents by default. There are two ways to make them. The quick one is to place a single \addcontentsline line just before each list command. Note that tocloft itself does not provide this automatic insertion.
\cleardoublepage
\addcontentsline{toc}{chapter}{\listfigurename} % 図目次を目次に載せる
\listoffigures
\cleardoublepage
\addcontentsline{toc}{chapter}{\listtablename} % 表目次を目次に載せる
\listoftablesThe other way is to load the **tocbibind** package (also by Peter Wilson). With \usepackage{tocbibind} it automatically adds whichever of the contents, list of figures, list of tables, bibliography, and index exist to the table of contents. You switch individual ones off with options — nottoc (exclude the contents itself), notlot (the list of tables), notlof (the list of figures), notbib (the bibliography), and notindex (the index). It is safer than placing \addcontentsline by hand, especially for a multi-page bibliography or index, and removes the need for the manual lines.
Finer control — titletoc and etoc
When you need to go beyond tocloft, two options stand out. **titletoc** (by Javier Bezos, part of the bundle with titlesec) defines the formatting of each contents line per level, including the material and separators before and after a line. It offers powerful hooks for shaping lines independently and pairs naturally with documents whose headings are styled by titlesec.
etoc (by Jean-François Burnol) goes further still, letting you redesign the contents entirely through a framework of “line styles” and “global styles.” Its highlight is \localtableofcontents**, which typesets a partial contents for each chapter from the same .toc, and it can even render the contents as a tree or a mind map. A good order is to start with tocloft, and move on to titletoc or etoc only when you want to rework the structure itself.