避免行和引用环境之间的分页符

避免行和引用环境之间的分页符

我在用LaTeX写作业的时候遇到了一点问题,我写了如下代码:

\documentclass{article}
\begin{document}
\center{Title}
\vspace{18cm}\\
This line should be on the same page as the next one.
\begin{quote}
This line should be on the same page as the previous one.\\
This one could be broken to another page if needed.
\end{quote}
\end{document}  

但是 LaTeX 会在第一行之后就断页,我想避免这种情况。\nopagebreak\\*似乎都不适合我。 有什么建议吗? 提前谢谢。

答案1

列表环境会插入一个(负数)\@beginparpenalty,这反而会鼓励在该点处分页。您可以(本地或全局)将其设置为 10000 以阻止分页。

我还修改了\center并删除了\\永远不应跟随的\vspace

\documentclass{article}
\begin{document}
\begin{center}Title\end{center}

\vspace{18cm}
This line should be on the same page as the next one.
\csname @beginparpenalty\endcsname10000
\begin{quote}
This line should be on the same page as the previous one.\\
This one could be broken to another page if needed.
\end{quote}
\end{document} 

答案2

一种方法是使用包裹needspace指定要保留多少行。

代码:

\documentclass{article}
\usepackage{needspace}
\begin{document}
\center{Title}
\vspace{18cm}\\
\needspace{3\baselineskip}% <------- Page break added if space less than 3\baselineskip
This line should be on the same page as the next one.
\begin{quote}
This line should be on the same page as the previous one.\\
This one could be broken to another page if needed.
\end{quote}
\end{document}

答案3

环境quote在内部表示为一个列表,而问题的技巧是“如何防止在逐项列表之前出现分页符?“也适用于quote环境:

\documentclass{article}
\makeatletter 
\newcommand\mynobreakpar{\par\nobreak\@afterheading} 
\makeatother
\begin{document}
\center{Title}
\vspace{18cm}\\
This line should be on the same page as the next one.\mynobreakpar
\begin{quote}
This line should be on the same page as the previous one.\\
This one could be broken to another page if needed.
\end{quote}
\end{document}

无关:\\后面的\vspace对我来说看起来很奇怪。也许应该将其删除?

相关内容