返回ConTeXt 内的标题目录 Table of Contents目录是文档中各部分的列表,包含各部分的章节标题和所在页的页码。有助于读者粗略了解文章内容,快速检索关键信息,直达对应页。
目录可以通过\placecontent或者\completecontent创建,并且根据使用命令的位置来决定显示全部 SECTION 还是部分 SECTION。\placecontent和\completecontent区别是\completecontent可以显示目录标题。
目录的显示范围
在 chapter 开始之前使用\placecontent或\completecontent, 目录会显示所有的标题。
\placecontent
\setuphead[section][page=no,conversion=A,sectionsegments=3]
\setuphead[subsection][page=no,conversion=i,sectionsegments=4]
\chapter[chapter1]{Chapter 1}
……
目录列表默认包含所有 SECTION,我们可以通过\setupcombinedlist中的 LIST 来设置目录列表包含的标题层级范围。
比如设置只显示 chapter 和 section 的层级
\completecontent[list={chapter,section},alternative=c]
在 chapter 开始以后,章节内使用\placecontent会显示此章内的 section 及以下的目录结构。
\chapter[chapter1]{Chapter 1}
\placecontent
\section{Section 1}
\subsection{Sub 1}
……
目录的标题
\completecontent在生成目录列表时,会自动在目录前放目录标题,默认的目录标题是 Contents,可以使用\setupheadtext来更改目录名称。
\setupheadtext[content=Table of Contents]
\completecontent[alternative=c]
因为\placecontent不负责写目录标题,可以自己写标题,和 setupheadtext 相比也增加了灵活性
{\midaligned {\bfc Table of Contents}}\blank[1cm]
\placecontent
目录的整体样式
\placecontent和\completecontent中的 alternative 可以更改目录的整体样式。
alternative |
目录结构 |
样式 |
a |
编号 标题 页码 (一行一个) |
|
b |
编号 标题 页码 (一行一个) |
|
c |
编号 标题 …… 页码 (一行一个) |
|
d |
编号 标题 页码 (一行多个) |
|
e |
标题(framed) |
|
f |
标题 |
|
g |
标题(居中显示) |
|
层级标题的样式
可以对目录列表内的每个层级标题设置不同的样式,每层级的样式分别使用\setuplist来设置。
\define[1]\numstyle
{
({\darkgreen #1})
}
\setupheadtext[content=Table of Contents]
\setuplist
[chapter]
[before=\blank[6pt], after=\blank[8pt], numberstyle={\bf\darkred}, textstyle={\bfb\darkred}]
\setuplist
[section]
[margin=2em,numbercommand=\numstyle]
\setuplist
[subsection]
[margin=4em,numbercommand=\numstyle]
\completecontent[alternative=c]
更方便的样式设置
我们也可以使用\placelist和\setuplist的参数来更方便迅速的添加目录列表。第一组参数设置目录包含的标题范围,第二组设置目录列表样式。
\placelist
[chapter,section]
[criterium=all,alternative=c,chapternumber=yes,numbercommand=\numstyle]
对于需要交互式目录的同学,可以在tex文件内加上\setupinteraction[state=start]。这样就可以在阅读 pdf 时点击目录某一行跳转到对应页面区域了。