删除目录中特定章节标题的缩进

删除目录中特定章节标题的缩进

问题:

我希望目录中的某些章节标题可以缩进,其他章节标题则不缩进。

最小工作示例:

\documentclass{book}

\usepackage[titles]{tocloft}

\newcommand*{\disableboldchapterintoc}{%
  \addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}}
  \addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}}
  \addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}}% 
}

%: ----------------------- Table of contents ------------------------
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchapfont}{\normalfont\bfseries}% titles in bold
\renewcommand{\cftchappagefont}{\normalfont\bfseries}% page numbers in bold
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\bfseries\cftdotfill{\cftsecdotsep}}% dot leaders in bold

\begin{document}

\tableofcontents
\chapter{Test Chapter One}
\section{Test Section One}

\pagenumbering{Roman}
\setcounter{page}{1}
\disableboldchapterintoc
\addcontentsline{toc}{chapter}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam}

\end{document}

输出:

在此处输入图片描述

期望输出:

tempor虽然测试第一章和测试第一部分可以缩进,但我希望以和开头的句子veniam不要缩进。

答案1

您可以将其添加到现有的\disableboldchapterintoc宏中:

\documentclass{book}

\usepackage[titles]{tocloft}

\newcommand*{\disableboldandindentchapterintoc}{%
  \addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}}
  \addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}}
  \addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}}% 
  \addtocontents{toc}{\string\setlength{\protect\cftchapnumwidth}{0pt}}
}

%: ----------------------- Table of contents ------------------------
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchapfont}{\normalfont\bfseries}% titles in bold
\renewcommand{\cftchappagefont}{\normalfont\bfseries}% page numbers in bold
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\bfseries\cftdotfill{\cftsecdotsep}}% dot leaders in bold

\begin{document}

\tableofcontents
\chapter{Test Chapter One}
\section{Test Section One}

\pagenumbering{Roman}
\setcounter{page}{1}
\disableboldandindentchapterintoc
\addcontentsline{toc}{chapter}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam}

\end{document}

在此处输入图片描述 再说一次,如果您只是想在目录中插入一些文本,您可以chapter首先避免使用:

\documentclass{book}

\usepackage[titles]{tocloft}

\begin{document}

\tableofcontents
\chapter{Test Chapter One}
\section{Test Section One}

\documentclass{book}

\pagenumbering{Roman}
\setcounter{page}{1}
\addtocontents{toc}{\noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam\par}

\end{document}

在此处输入图片描述

相关内容