2010-10-20 38 views
8

我在寫一個文檔,我不希望在TOC中顯示小節編號(我希望小節標題在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 

我使用\ 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條目中獲取?

回答

4

在乳膠例子(使用「文章」類),我得到這個在.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% 

我只是複製粘貼的\@dottedtoclinelatex.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}} 
+0

我只想說這對我非常有幫助。謝謝! – Tyr 2011-03-31 03:32:51

2

我不知道這樣做的程序化方式,但我知道您可以進入爲您的文檔生成的* .toc文件,並刪除要禁止的部分的節號參數。

你可以改變這一點:

\contentsline {subsection}{\tocsubsection {}{1.1}{subsection one}}{1} 

要這樣:

\contentsline {subsection}{\tocsubsection {}{}{subsection one}}{1} 

以生成你想要的東西。注意,每次編譯tex源時都會重新生成。

+0

謝謝,我會如果保持這種作爲備份,沒有任何編程方式。 – nbz 2010-10-20 14:31:49

+0

儘管在.toc文件中進行更改後您確實需要構建一次輸出以查看更改的效果。 – nbz 2010-10-28 14:10:39

+0

對不起,我不得不改變我接受的答案。 Sparshong的作品非常好,並且以程序化的方式非常乾淨地完成。但是在此之前,你的工作很快就做好了! – nbz 2011-06-22 14:32:02