Tools for Automation: Table of Contents #
Author: Erhua
Keywords: automation tools, table of contents
In this section, we discuss the automatic generation of table of contents. We can generate a table of contents by using the command \tableofcontents
after setting the desired headings.
Customized Table of Contents #
We have previously discussed how to customize the format of table of contents: Customizing Headings
Type | Command | Note |
---|---|---|
List of Figures | \listoffigures |
Titles produced by \caption command |
List of Tables | \listoftables |
Titles produced by \caption command |
By default, items such as the table of contents itself, bibliography, and index are not automatically included in the table of contents. We can control their appearance using the tocbibind
package, which has optional arguments (all visible by default):
Optional Argument | Explanation |
---|---|
notbib | Exclude bibliography |
notindex | Exclude index |
nottoc | Exclude chapter headings |
not lot | Exclude list of tables |
notlof | Exclude list of figures |
For more details, please refer to the tocbibind
package.
Other packages that can be used for table of contents customization are:
\usepackage{tocbibind}
\usepackage{titletoc}
\usepackage{minitoc}
\usepackage{tocloft}
Customizing the Format of the Table of Contents #
To customize the format of the table of contents, we can use the following packages:
\usepackage{tocloft} % Simple syntax for customizing format
\usepackage{titletoc} % More complex package for customizing the table of contents
Explanation: The lengths of the space before and after the heading are variables that can be modified using \setlength
. The rest are macros that need to be redefined using \renewcommand
.
For specific modifications to font family, font size, etc., we can refer to the relevant content of the tocloft
package (please consult the package documentation).
Examples:
\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} % Set the font family and size of "Table of Contents"
\renewcommand{\cftchapfont}{\qingsong\muluchap} % Set the font family and size of "Chapter"
\renewcommand{\cftsecfont}{\qingsong} % Set the font family of "Section"
\renewcommand{\cftsubsecfont}{\qingsong} % Set the font family of "Subsection"
\setlength{\cftbeforetoctitleskip}{5mm} % Set the distance between "Table of Contents" and top margin
\setlength{\cftaftertoctitleskip}{10mm} % Set the distance between "Table of Contents" and the main text
\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 the Layout of the Table of Contents #
Apart from customization options, we can also customize the layout of the table of contents. See the image:
Due to limited usage, please refer to the package documentation for more details.