在乳膠例子(使用「文章」類),我得到這個在.toc文件:
\contentsline {section}{\numberline {1}test section without number}{1}{section.1}
這裏最重要的部分是\numberline
宏。將其重新定義爲像
\def\numberline#1{}
將刪除toc中的所有編號,而不是其他地方。 如果你喜歡的東西\tocsubsection
在替代的.toc(見其他答案),那麼你也許可以這樣做:
\let\oldtocsubsection=\tocsubsection
\def\tocsubsection#1#2#3{\oldtocsubsection{#1}{}{#3}}
然而,這將刪除所有數字在表的內容。如果要控制編號在哪個級別消失,\contentsline
宏根據上下文擴展爲不同的宏,例如\[email protected]
。這些宏反過來使用通用的\@dottedtocline
宏。這是您需要修改的一個,我們將在其中有條件地重新定義\numberline
。
要對深度控制在其停止顯示的數字,讓我們定義一個新的計數器:
\newcounter{sectocnonumdepth}
\setcounter{sectocnonumdepth}{2}
那麼條件重新定義將是繼線(從代碼中提取更多的可讀性)。
\ifnum #1>\[email protected] \def\numberline##1{}\fi%
我只是複製粘貼的\@dottedtocline
從latex.ltx
源文件中的定義,並增加了內部檢查。這裏是整個示例代碼:
\newcounter{sectocnonumdepth}
\setcounter{sectocnonumdepth}{2}
\makeatletter
\def\@dottedtocline#1#2#3#4#5{%
\ifnum #1>\[email protected] \else
\vskip \[email protected] \@plus.2\[email protected]
{\ifnum #1>\[email protected] \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{$\[email protected]
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill
\nobreak
\[email protected]@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
\par}%
\fi}
\makeatother
最後一點:這將使部分和小節的標題在同一水平位置開始,因爲沒有數字顯示。如果您想了解更多的填充,可以爲實例添加到\quad
的\numberline
新定義,或使用,甚至只用#1
除去最初的定義:
\def\numberline##1{\[email protected]@\@tempdima{\hfil}}
我只想說這對我非常有幫助。謝謝! – Tyr 2011-03-31 03:32:51