问题:
我希望目录中的某些章节标题可以缩进,其他章节标题则不缩进。
最小工作示例:
\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}