每页有多个章节,只要它们“合适”

每页有多个章节,只要它们“合适”

我正在排版一本书,其中有一些非常短的章节。如果两个连续的章节足够短,我希望将它们都放在同一页上。否则,下一章应该总是从下一页开始。

作为奖励,如果长度超过一页的章节可以在分页符之前允许新的章节,并且仅当后续章节能够完全适合当前章节的最后一页而不需要另一个分页符,那就太好了。

这可能吗?

答案1

\chapter以下只是一个给出一般想法的例子。它包含适用于标准的命令补丁类;对于其他文档类,补丁可能(并且通常会)有所不同。当然,电子工具箱可以\patchcmd改用 。

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\makeatletter

\renewcommand\chapter{%
%   \if@openright\cleardoublepage\else\clearpage\fi
  \vfil \penalty-9000 \vfilneg
% Something from the following two lines could be retained:
%   \thispagestyle{plain}%
%   \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter
}

\makeatother

% \tracingpages = 1



\begin{document}

\chapter{First}
\lipsum[1-16]

\chapter{Second}
A very short chapter.

\chapter{Third}
Another very short chapter.

\chapter{Fourth}
This is true minimalism.

\chapter{Fifth}
\lipsum[17-20]

\chapter{Sixth}
\lipsum[21]

\chapter{Seventh}
\lipsum[22]

\chapter{Eighth}
\lipsum[23-24]

\chapter{Ninth}
\lipsum[25-32]

\chapter{Tenth}
And so on\ldots

\end{document}

编辑

再举一个例子,对于回忆录类(明确要求),补丁将是:

\documentclass[a4paper]{memoir}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\makeatletter

\renewcommand\chapter{%
  % Do not remove support for "article" option:
  \ifartopt\par\@nameuse{chapterblock}\else
%     \clearforchapter
    \vfil \penalty-9000 \vfilneg
% Something from the following two lines could be retained:
%     \thispagestyle{chapter}
%     \global\@topnum\z@
  \fi
  \m@mindentafterchapter
  \@ifstar{\@m@mschapter}{\@m@mchapter}%
}

\makeatother

% \tracingpages = 1



\begin{document}

\chapter{First}
\lipsum[1-16]

\chapter{Second}
A very short chapter.

\chapter{Third}
Another very short chapter.

\chapter{Fourth}
This is true minimalism.

\chapter{Fifth}
\lipsum[17-20]

\chapter{Sixth}
\lipsum[21]

\chapter{Seventh}
\lipsum[22]

\chapter{Eighth}
\lipsum[23-24]

\chapter{Ninth}
\lipsum[25-32]

\chapter{Tenth}
And so on\ldots

\end{document}

等等…

相关内容