用tocloft
包定义新目录
在LaTeX中,有三个命令\tableofcontents
,\listoftables
,\listoffigures
,分别用来生成章节目录,表格目录和插图目录。但有时候我们需要生成其他目录,比如书籍中的例题目录,这个时候我们可以利用tocloft
包自定义一个例题目录。tocloft
包提供了\newlistof
命令,其格式如下:1
\newlistof[已有计数器count1]{计数器count2}{扩展名}{目录名称}
其中前两个参数等价于命令\newcounter[count1]{count2}
,就是让第二个计数器绑定在第一个计数器,并随着第一个计数器的递增而归零。我们给出一个最小工作示例如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28\documentclass[UTF8]{ctexart}
\usepackage{tocloft}
\newcommand\listexamplename{例题目录}
\newlistof[section]{exam}{ex}{\listexamplename}
\newenvironment{example}{
\refstepcounter{exam}
}{\par}
\newcommand{\exam}[1]{%
\par\noindent\textbf{例 \theexam. #1}
\addcontentsline{ex}{exam}{\protect\numberline{\theexam}#1}\par
}
\usepackage[hidelinks]{hyperref}
\begin{document}
\listofexam
\section{第一节}
\begin{example}\exam{勾股}
勾股定理
\end{example}
\section{第二节}
\begin{example}\exam{歌德}
哥德巴赫猜想
\end{example}
\section{第三节}
\begin{example}\exam{黎曼}
黎曼猜想
\end{example}
\end{document}
和一般的目录一样,需要编译两次,即可生成正确的例题目录。在导言区加入以下代码可生成双栏目录1
2
3\usepackage{multicol}
\renewcommand\cftexprehook{\begin{multicols}{2}}
\renewcommand\cftexposthook{\end{multicols}}