Automated Processing Tools: Table of Contents #
Author: Erhua
Keywords: automation tools, table of contents
In this section, we discuss the automatic generation of a table of contents. We use the \tableofcontents
command to generate the table of contents for the predefined headings.
Customizing Table of Contents Generation #
We have previously discussed controlling the format of the table of contents titles: Customizing Titles
Type | Command | Note |
---|---|---|
List of Figures | \listoffigures |
Titles generated by \caption |
List of Tables | \listoftables |
Titles generated by \caption |
By default, the table of contents itself, as well as the bibliography and index, are not automatically included in the table of contents. We can use the tocbibind
package to control whether they appear. This package has optional parameters to control this behavior (by default, all are shown).
Optional parameters:
Optional Parameter | Description |
---|---|
notbib | Exclude the bibliography |
notindex | Exclude the index directory |
nottoc | Exclude the section catalog |
not lot | Exclude the table directory |
notlof | Exclude the figure directory |
For more details, please refer to the tocbibind
package.
Other packages that can be used for the table of contents are:
\usepackage{tocbibind}
\usepackage{titletoc}
\usepackage{minitoc}
\usepackage{tocloft}
Customizing Table of Contents Format #
Customizing the format of the table of contents is usually done using packages.
\usepackage{tocloft} % Simple syntax and customization
\usepackage{titletoc} % More complex table of contents customization
Explanation: The lengths for the spacing before and after the title are variables and can be modified using the \setlength
command. The rest are macros that need to be redefined using the \renewcommand
command.
For specific modifications such as font family and font size, please refer to the relevant sections in the documentation of the tocloft
package.
Example:
\documentclass[]{book}
\usepackage[heading = true]{ctex}
\usepackage{anyfontsize}
\newcommand{\muluchap}{\fontsize{20pt}{15pt}\selectfont}
\newcommand{\mulutit}{\fontsize{35pt}{25pt}\selectfont}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\qingsong\mulutit} % Sets the font family and size for "Table of Contents"
\renewcommand{\cftchapfont}{\qingsong\muluchap} % Sets the font family and size for "Chapter"
\renewcommand{\cftsecfont}{\qingsong} % Sets the font family for "Section"
\renewcommand{\cftsubsecfont}{\qingsong} % Sets the font family for "Subsection"
\setlength{\cftbeforetoctitleskip}{5mm} % Sets the distance between the "Table of Contents" and the top margin
\setlength{\cftaftertoctitleskip}{10mm} % Sets the distance between the "Table of Contents" and the contents
\newCJKfontfamily\qingsong{FZQKBYSJW--GB1-0}
\ctexset{section={name={第,节},titleformat = {\qingsong}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[paperwidth = 200mm,paperheight = 150mm]{geometry}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\chapter{锦瑟1}
\section{锦瑟无端五十弦}
\subsection{一弦一柱思华年}
\lipsum[3-5]
\newpage
\chapter{锦瑟2}
\section{庄生晓梦迷蝴蝶}
\subsection{望帝春深托杜鹃}
\lipsum[3-5]
\end{document}
Customizing Table of Contents Layout #
In addition to customization, we can also customize the layout of the table of contents. See the image below:
Since it is less commonly used, please refer to the package documentation for more details.