刪除目錄中章節標題的第一個單字

刪除目錄中章節標題的第一個單字
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\section{Term: Foo}
\section{foobar}
\section{Term: Bar}
\end{document}

我的一些章節標題以特殊單字開頭。在我的範例中,它是文字“Term:”。當然,這是整個標題的一部分。但我希望它們不要出現在目錄中:

目前目錄:

1 MyChapter               3
  1.1 Term: Foo ..........3
  1.2 foobar .............3
  1.3 Term: Bar ..........3

預期目錄:

1 MyChapter               3
  1.1 Foo ................3
  1.2 foobar .............3
  1.3 Bar ................3

當然,一個以其他方式工作的解決方案也很棒:如果有一個解決方案可以在我的章節標題中添加“Term:”前綴,那麼這也可以工作。但在這種情況下,需要確保只有少數標題部分需要擴充。

答案1

你可以簡單地做:

\section*{Term: Foo}                  % suppresses output in TOC
\addcontentsline{toc}{section}{Foo}   % add custom line to TOC

編輯:上面的程式碼也抑制了編號,您可能不希望這樣做。所以這裡有另一個建議,用一個命令來完成這一切:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newcommand{\customsec}[1]{\section[#1]{Term: #1}}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\customsec{Foo}
\section{foobar}
\customsec{Bar}
\end{document}

總有機碳 內容

答案2

您可以使用短標題作為命令中的可選參數\section。這保留了編號。微量元素:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\section[Foo]{Term: Foo}
\section{foobar}
\section[Bar]{Term: Bar}
\end{document}

結果:

在此輸入影像描述

相關內容