如何防止环境的最后三行出现分页符?

如何防止环境的最后三行出现分页符?

我想创建一个环境,其内容不应该允许在最后一段的最后三行出现分页符。

如果环境中文本的最后三行到达页面边框,则分页符应发生在倒数第四行之后。

在环境之外,分页符的正常行为不应改变。

环境将仅包含普通文本,但左右两侧的边距会增加。可能还会出现一些内联数学公式,但应该就是这样。

\documentclass{scrartcl}

\usepackage{lipsum}

\newenvironment{env}{%
    \begin{addmargin}{2em}%
}{%
    \end{addmargin}
}%


\begin{document}
\lipsum[1-3]

\begin{env}
    \lipsum[1]
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
\end{env}
\end{document}

编辑:

我不确定,如果我能说清楚的话,我想要实现什么:我通常不知道最后一行究竟从哪里开始。相反,它更像是为了防止出现孤行,但不仅要防止段落的最后一行跳转到下一页,而且环境中的最后三行文本{env}应始终保持在一起,无论是在实际页面上还是在下一页上。

答案1

您可以使用\widowpenalties; 与

\widowpenalties 3 10000 10000 0

在最后三行之间添加 10000 的惩罚,而在前面几行之间不添加。另请参阅如何避免段落内分页?

\documentclass{scrartcl}

\usepackage{lipsum}

\newenvironment{env}
 {\begin{addmargin}{2em}\widowpenalties 3 10000 10000 0 }
 {\end{addmargin}}


\begin{document}
\lipsum[1-3]

\begin{env}
    \lipsum[1]
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
\end{env}
\end{document}

在此处输入图片描述

相关内容