乳胶,TOC中的NO部分编号,但在实际部分标题中可见

nbz*_*nbz 8 latex

我正在编写一份文件,我不希望在TOC中显示分段编号(我希望在TOC中显示小节标题),但我希望分段编号显示在实际文档标题中.

这就是我要的

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
Run Code Online (Sandbox Code Playgroud)

我尝试使用\ 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
Run Code Online (Sandbox Code Playgroud)

是否可以在文档标题中获取节号但不在TOC条目中?

Spa*_*ong 5

在乳胶示例中(使用“文章”类),我在 .toc 文件中得到了这个:

\contentsline {section}{\numberline {1}test section without number}{1}{section.1}
Run Code Online (Sandbox Code Playgroud)

这里的重要部分是\numberline宏。将它重新定义为空的东西

\def\numberline#1{}
Run Code Online (Sandbox Code Playgroud)

将删除目录中的所有编号,而不是其他地方。如果您\tocsubsection在 .toc 中得到类似的内容(请参阅其他答案),那么您可能可以执行以下操作:

\let\oldtocsubsection=\tocsubsection
\def\tocsubsection#1#2#3{\oldtocsubsection{#1}{}{#3}}
Run Code Online (Sandbox Code Playgroud)

但是,这会删除目录中的所有数字。如果您想控制编号消失的级别,\contentsline宏会根据上下文扩展为不同的宏,例如\l@section. 这些宏依次使用通用\@dottedtocline宏。这是您需要修改的,我们将有条件地重新定义\numberline.

为了控制停止显示数字的深度,让我们定义一个新的计数器:

\newcounter{sectocnonumdepth}
\setcounter{sectocnonumdepth}{2}
Run Code Online (Sandbox Code Playgroud)

然后条件重定义将遵循以下行(从代码中提取以提高可读性)。

 \ifnum #1>\c@sectocnonumdepth \def\numberline##1{}\fi%
Run Code Online (Sandbox Code Playgroud)

我只是简单地\@dottedtoclinelatex.ltx源文件中复制粘贴了 的定义,并在里面添加了检查。这是整个示例的代码:

\newcounter{sectocnonumdepth}
\setcounter{sectocnonumdepth}{2}


\makeatletter
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\ifnum #1>\c@sectocnonumdepth \def\numberline##1{}\fi%
     \leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi}
\makeatother
Run Code Online (Sandbox Code Playgroud)

最后注意:这将使节和小节的标题从同一水平位置开始,因为没有数字可显示。如果你想要更多的填充,你可以例如添加\quad到 的新定义\numberline,或者甚至使用仅#1删除的原始定义:

\def\numberline##1{\hb@xt@\@tempdima{\hfil}}
Run Code Online (Sandbox Code Playgroud)