Latex,目录中没有章节编号,但在实际章节标题中可见
我正在编写一个文档,我不希望在目录中显示小节编号(我希望小节标题在目录中可见),但我希望在实际文档标题中显示小节编号。
这就是我想要的,
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
1.1.1 Subsection One
Some text
我尝试使用 \setcounter{secnumdepth}{1} 但这甚至从节标题中删除了数字,所以我所拥有的是,
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
Subsection One
Some text
是否可以在文档标题中获取节号,但不能在 TOC 条目中获取节号?
I am writing a document where I do not want subsection numbering to show in the TOC (I want the subsection heading visible in the TOC) but I want the subsection numbering to show in the actual document heading.
This is what I want
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
1.1.1 Subsection One
Some text
I tried using \setcounter{secnumdepth}{1} but this removes the number even from the section heading so what I have is,
Table of Contents
1. Chapter One
1.1 Section One
SubSection One
Chapter 1
Chapter One
Some chapter text
1.1 Section One
Some text
Subsection One
Some text
Is it possible to get the section number in the document heading but not in the TOC entry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在乳胶示例中(使用“article”类),我在 .toc 文件中得到了这个:
这里的重要部分是
\numberline
宏。将其重新定义为空的内容会删除目录中的所有编号,而不是其他地方的编号。
如果您在 .toc 中得到类似
\tocsubsection
的内容(请参阅其他答案),那么您可能可以执行以下操作:但是,这会删除表中的所有数字内容。如果您想控制编号在哪个级别消失,则
\contentsline
宏会根据上下文扩展为不同的宏,例如\l@section
。这些宏依次使用通用的\@dottedtocline
宏。这是您需要修改的,我们将有条件地重新定义\numberline
。为了控制停止显示数字的深度,让我们定义一个新的计数器:
然后条件重新定义将在下面一行(从代码中提取以提高可读性)。
我只是从
latex.ltx
源文件中复制粘贴\@dottedtocline
的定义,并在其中添加了检查。以下是整个示例的代码:最后注意:这将使节和子节的标题从相同的水平位置开始,因为没有要显示的数字。如果您想要更多填充,您可以将
\quad
添加到\numberline
的新定义中,或者甚至使用仅包含#1 的原始定义删除:
In a latex example (using the "article" class), I get this in the .toc file:
The important part here is the
\numberline
macro. Redefining it to something empty likewill remove all numberings in the toc and not elsewhere.
If you get something like
\tocsubsection
instead in the .toc (see other answer), then you can probably do something like:However, this removes all numbers in the table of contents. If you want to control at which level the numbering disappear, the
\contentsline
macro expands to different macros depending on the context, e.g.,\l@section
. Those macros in turn use the generic\@dottedtocline
macro. This is the one you need to modify, in which we will conditionally redefine\numberline
.To have control on the depth at which to stop displaying numbers, let us define a new counter:
Then the conditional redefinition will be following line (extracted from the code for more readability).
I simply copy-pasted the definition of
\@dottedtocline
from thelatex.ltx
source file, and added the check inside. Here is the code for the whole example:Final note: this will make the title of section and subsection to start at the same horizontal position, since there is no number to display. If you want more padding, you can for instance add
\quad
to the new definition of\numberline
, or to even use the original definition with just the#1
removed:我不确定执行此操作的编程方式,但我确实知道您可以进入为文档生成的 *.toc 文件,并删除要抑制的部分的节号参数。
您可以将其更改为:
更改为:
这将生成您想要的内容。请注意,每次编译 tex 源时都会重新生成它。
I'm not sure of a programmatic way of doing this, but I do know that you can go into the generated *.toc file for your document and remove the section number argument for the section that you want to suppress.
You can change this:
To this:
Which will generate what you want. Watch out, this gets regenerated each time you compile your tex source.