有许多示例\nopagebreak
并未按预期工作:
有效果的案例有哪些\nopagebreak
? 决定是否有效的规则是什么\nopagebreak
?
答案1
\nopagebreak
这使得在这一点上中断变得非常糟糕。因此 TeX 不会中断在那个节点然而,从视觉上看,它可能会在那一点上断裂,例如
blah blah
\nopagebreak
\hrule height 0pt
\pagebreak[2]
blah blah
那么 TeX 不会在不可见规则之上中断,但可能会在不可见规则之后中断。因此,添加似乎\nopagebreak
没有起作用。
在复杂的宏(如添加多个惩罚和空格的节标题)中,每个宏都会单独引入一个潜在的断点,因此很难通过单个宏来防止分页,\nopagebreak
但细节取决于宏的具体细节,以及它插入垂直空间和惩罚的位置。
\nopagebreak
在回答评论中的问题时,通常只要该页面上有另一个可行的断点,单个断点就会阻止分页,例如,如果您取消注释\pagebreak
此处,则可以通过将两行额外的行移到下一页来避免该点的断页。
\documentclass{article}
\setlength\textwidth{5cm}
\setlength\textheight{16cm}
\begin{document}
\section{zzz}
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
\section{zzz}
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
\section{zzz}
abc\par one two three four one two three four one two three four
abc\par%\nopagebreak
one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
\end{document}