为一个三明治论点,我正在排版论文列表使用托克洛夫特包。每个条目包含完整的引用(使用比布拉特克斯's \fullcite
),因此它可能相当长。我目前将其排版如下(其中\makeanypaperBiblio
是自定义函数的参数):
\addcontentsline{pap}{papers}{%
{\bfseries Paper~\numberline{\Roman{paper}}}\\[.25\baselineskip]%
\fullcite{\makeanypaperBiblio}\vspace{2ex}}%
我想确保整个内容行都在我的论文列表,但通常的防止分页符的方法不起作用。为了说明这个问题,平均能量损失:
\documentclass[a5paper]{article}
\begin{document}%
\tableofcontents
\section{Test}
\addcontentsline{toc}{section}{Very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very long}
\addcontentsline{toc}{section}{Very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very long}
\addcontentsline{toc}{section}{\begin{samepage}Very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very very very very very very very very very very
very very very very very very long\end{samepage}}
\end{document}
编译此示例失败,并显示:
! Argument of \@sect has an extra }.
<inserted text>
\par
l.31 ...ry very very very very long\end{samepage}}
?
Runaway argument?
显然,我无法使用samepage
内的环境addcontentsline
,或者至少不能不耍花招。如何防止目录条目跨越多页?
答案1
您需要保护命令:
\addcontentsline{toc}{section}{\protect\samepage Very very very very very very ...long}
如果您想将其插入所有章节标题,您可以重新定义\l@section
例如
\makeatletter
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.5em}%
\begingroup
\samepage %new
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\makeatother