![避免行和引用环境之间的分页符](https://linux22.com/image/268924/%E9%81%BF%E5%85%8D%E8%A1%8C%E5%92%8C%E5%BC%95%E7%94%A8%E7%8E%AF%E5%A2%83%E4%B9%8B%E9%97%B4%E7%9A%84%E5%88%86%E9%A1%B5%E7%AC%A6.png)
我在用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
对我来说看起来很奇怪。也许应该将其删除?