![删除目录中特定章节标题的缩进](https://linux22.com/image/372045/%E5%88%A0%E9%99%A4%E7%9B%AE%E5%BD%95%E4%B8%AD%E7%89%B9%E5%AE%9A%E7%AB%A0%E8%8A%82%E6%A0%87%E9%A2%98%E7%9A%84%E7%BC%A9%E8%BF%9B.png)
问题:
我希望目录中的某些章节标题可以缩进,其他章节标题则不缩进。
最小工作示例:
\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}