目录中的换行符

目录中的换行符

我需要你帮助我完成代码:

\documentclass[12pt]{article}
\usepackage{tocloft}
\renewcommand{\cftsecafterpnum}{\linebreak}
\cftsetrmarg{7em}% Default is 2.55em
\begin{document}
\tableofcontents
\section{xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx}
\section{yyy}
\end{document}

我之所以写这个命令,\renewcommand{\cftsecafterpnum}{\linebreak}是因为我需要目录中两个部分之间的额外一行。但这个命令也会将页码移近标题。我该如何避免这种情况?我希望它像这样(带有红色的“1”):

在此处输入图片描述

答案1

\cftsecafterpnum你需要做的不是重新定义,而是重新定义\cftsecaftersnum——参见托克洛夫特手册中提供了“控制章节条目排版的用户命令”的完整列表。(遗憾的是,手册中仅粗略地描述了许多命令的用途,因此需要进行一些猜测。)

更详细地说,如果你改用

\renewcommand\cftsecaftersnum{\newline}

那么你的 MWE 会产生:

在此处输入图片描述

完整代码如下:

\documentclass[12pt]{article}
\usepackage{tocloft}
\renewcommand\cftsecaftersnum{\newline}
\cftsetrmarg{7em}% Default is 2.55em
\begin{document}
\tableofcontents
\section{xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx}
\section{yyy}
\end{document}

相关内容