楼主: oliyiyi
11329 1

LaTeX技巧:在 LaTeX 中将不编号的章节列入目录 [推广有奖]

版主

泰斗

0%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
271951 个
通用积分
31269.3519
学术水平
1435 点
热心指数
1554 点
信用等级
1345 点
经验
383775 点
帖子
9598
精华
66
在线时间
5468 小时
注册时间
2007-5-21
最后登录
2024-4-18

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
LaTeX技巧:在 LaTeX 中将不编号的章节列入目录


LaTeX 标准文档类提供了 \section 和 \section* 等两组命令,用于排版章节标题。其中不带星号的版本有章节编号,会列入目录,同时修改章节标记。带星号的版本只有章节标题格式而不编号,不列入目录,也不会修改章节标记。

有时,我们会希望将不编号的章节标题列入目录。这种情况使用 \section 或 \section* 都不大合适。本文将对这些问题做出分析,并给出解决方案。

LaTeX 标准文档类的 \section 命令做四件事情:

  • 编号自增 1
  • 输出章节标题
  • 处理目录(和 PDF 书签)
  • 做页眉的章节标记

相应地,\section* 命令只做上述第二件事情,其余三件都不做。

因此,我们的思路很简单,有两个方向。第一,使用 \section*,手工做目录的处理;第二,使用 \section,但是抑制编号。

思路一

LaTeX 处理目录需要编译两次。在第一次编译的过程中,\section 命令将目录信息写入 .aux文件。随后,在第二次编译的过程中,LaTeX 读取 .aux 文件中的相应信息,形成目录。因此,我们只需要模仿 \section 写入 .aux 文件的过程就可以了。

LaTeX 提供了 \addcontentsline{< 辅助文件后缀 >}{< 章节等级 >}{名字} 命令来做这样的工作。我们来看一个例子。



[color=rgb(170, 170, 170) !important]1


[color=rgb(170, 170, 170) !important]2


[color=rgb(170, 170, 170) !important]3


[color=rgb(170, 170, 170) !important]4


[color=rgb(170, 170, 170) !important]5


[color=rgb(170, 170, 170) !important]6



\documentclass[color=rgb(51, 51, 51) !important]{ctexart[color=rgb(51, 51, 51) !important]}
\begin[color=rgb(51, 51, 51) !important]{document[color=rgb(51, 51, 51) !important]}
\tableofcontents
\section*[color=rgb(51, 51, 51) !important]{不编号的章节标题[color=rgb(51, 51, 51) !important]}
\addcontentsline[color=rgb(51, 51, 51) !important]{toc[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{section[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{不编号的章节标题[color=rgb(51, 51, 51) !important]}
\end[color=rgb(51, 51, 51) !important]{document[color=rgb(51, 51, 51) !important]}




思路二

LaTeX 标准文档类中的 \appendix 命令,会使得后续的章节标题从 0 开始编号,同时将编号格式从阿拉伯数字修改为大写英文字母。\appendix 命令虽然不符合我们的需求,但是产生的效果却和我们需要的效果类似:修改了章节标题编号。我们可以对这个命令做适当的修改,达成我们的目的。

我们来看一下 article.cls 里的 \appendix 是如何定义的。



[color=rgb(170, 170, 170) !important]1


[color=rgb(170, 170, 170) !important]2


[color=rgb(170, 170, 170) !important]3


[color=rgb(170, 170, 170) !important]4



\newcommand\appendix[color=rgb(51, 51, 51) !important]{\par
[color=rgb(0, 111, 224) !important]  \setcounter[color=rgb(51, 51, 51) !important]{section[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{0[color=rgb(51, 51, 51) !important]}[color=rgb(153, 153, 153) !important]%
[color=rgb(0, 111, 224) !important]  \setcounter[color=rgb(51, 51, 51) !important]{subsection[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{0[color=rgb(51, 51, 51) !important]}[color=rgb(153, 153, 153) !important]%
[color=rgb(0, 111, 224) !important]  \gdef\thesection[color=rgb(51, 51, 51) !important]{[color=rgb(51, 51, 51) !important]\@Alph\c[color=rgb(51, 51, 51) !important]@section[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]}



接下来,我们仿造它,定义一个新的命令 \specialsectioning。


[color=rgb(170, 170, 170) !important]1


[color=rgb(170, 170, 170) !important]2


[color=rgb(170, 170, 170) !important]3


[color=rgb(170, 170, 170) !important]4


[color=rgb(170, 170, 170) !important]5


[color=rgb(170, 170, 170) !important]6


[color=rgb(170, 170, 170) !important]7


[color=rgb(170, 170, 170) !important]8


[color=rgb(170, 170, 170) !important]9


[color=rgb(170, 170, 170) !important]10


[color=rgb(170, 170, 170) !important]11



\documentclass[color=rgb(51, 51, 51) !important][hyperref[color=rgb(51, 51, 51) !important][color=rgb(51, 51, 51) !important]{ctexart[color=rgb(51, 51, 51) !important]}
\newcommand\specialsectioning[color=rgb(51, 51, 51) !important]{\par
[color=rgb(0, 111, 224) !important]  \setcounter[color=rgb(51, 51, 51) !important]{section[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{0[color=rgb(51, 51, 51) !important]}[color=rgb(153, 153, 153) !important]%
[color=rgb(0, 111, 224) !important]  \setcounter[color=rgb(51, 51, 51) !important]{subsection[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]{0[color=rgb(51, 51, 51) !important]}[color=rgb(153, 153, 153) !important]%
[color=rgb(0, 111, 224) !important]  \renewcommand\thesection[color=rgb(51, 51, 51) !important]{\relax[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]}
\begin[color=rgb(51, 51, 51) !important]{document[color=rgb(51, 51, 51) !important]}
\tableofcontents
\section[color=rgb(51, 51, 51) !important]{正常编号的章节标题[color=rgb(51, 51, 51) !important]}
\specialsectioning
\section[color=rgb(51, 51, 51) !important]{不编号的章节标题[color=rgb(51, 51, 51) !important]}
\end[color=rgb(51, 51, 51) !important]{document[color=rgb(51, 51, 51) !important]}




编译之后我们会发现,在 \specialsectioning 之后的 \section 虽然不带星花,但已然不编号了,并且出现在了目录当中。

不过,正常标题的编号和标题正文之间是有一定的空距的。我们现在虽然将编号取消了,但是这个空距依然存在。虽然它不明显,但是毕竟是个问题。作为一个精益求精的完美主义者,我们要解决它。

正文中编号的格式由 LaTeX 内部宏 \@seccntformat 控制,默认是在编号后面加一个 \quad,我们把它去掉。



[color=rgb(170, 170, 170) !important]1



\def[color=rgb(51, 51, 51) !important]\@seccntformat##1[color=rgb(51, 51, 51) !important]{[color=rgb(51, 51, 51) !important]\@nameuse[color=rgb(51, 51, 51) !important]{the##1[color=rgb(51, 51, 51) !important]}[color=rgb(51, 51, 51) !important]}



选自:http://liam0205.me/2015/04/10/how-to-list-unnumbered-section-in-the-table-of-contents/




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:LaTeX atex Late ATE LAT 解决方案 技巧 手工 信息

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html
沙发
gaojianwqjk 发表于 2015-5-17 22:13:47 来自手机 |只看作者 |坛友微信交流群
oliyiyi 发表于 2015-5-17 21:52
LaTeX技巧:在 LaTeX 中将不编号的章节列入目录


:)

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 16:15