我的 ToC 章节标题存在类似以下问题很久以前就发布过一篇关于部分标题的帖子。我正在寻找有关如何将这些更改应用于章节标题的指导。我正在使用大学的样式文件,因此tocloft
目前使用并不实用。
以下是为长部分标题创建一致缩进的代码示例:
\documentclass{book}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%NEW
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\renewcommand*\l@part[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode\large\bfseries
\advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}\makeatother
\begin{document}
\tableofcontents
\part{Test part one with a really really long title spanning two lines}
\part{Test part two with a really really long title spanning two lines}
\part{Test part three with a really really long title spanning two lines}
\part{Test part four with a really really long title spanning two lines}
\end{document}
输出如下所示
答案1
因此,我所做的是:复制您的\renewcommand*\l@part…
,用 替换\l@part
并\l@chapter
删除\large
我在此命令中找到的 。所以现在它看起来像:
\documentclass{book}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%NEW
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\renewcommand*\l@part[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode\large\bfseries
\advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode\bfseries
\advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}\makeatother
\begin{document}
\tableofcontents
\part{Test part one with a really really long title spanning two lines}
\chapter{Test part one with a really really long title spanning two lines}
\chapter{Test part two with a really really long title spanning two lines}
\part{Test part two with a really really long title spanning two lines}
\part{Test part three with a really really long title spanning two lines}
\part{Test part four with a really really long title spanning two lines}
\end{document}
编辑:章节标题应该读作“测试第二章……”而不是“测试第二部分……”但你明白我的意思。