在absolutenopagebreak环境中避免垂直空格

在absolutenopagebreak环境中避免垂直空格

我喜欢这个想法绝对没有分页符环境,我想在需要时使用它来包装类似定理的环境(而不修改这些环境)。它确实有效,但问题是它会创建额外的垂直空间(前后)。

有没有办法来解决这个问题?

\documentclass{article}
\newtheorem{theorem}{Theorem}
\newenvironment{absolutelynopagebreak}
  {\par\nobreak\vfil\penalty0\vfilneg
   \vtop\bgroup}
  {\par\xdef\tpd{\the\prevdepth}\egroup
   \prevdepth=\tpd}

\begin{document}

\begin{theorem}
Statement 001.
\end{theorem}

\begin{theorem}
Statement 002.
\end{theorem}

\begin{absolutelynopagebreak}
\begin{theorem}
Statement 003.
\end{theorem}
\end{absolutelynopagebreak}

\begin{theorem}
Statement 004.
\end{theorem}

\begin{theorem}
Statement 005.
\end{theorem}

\end{document}

我能够使用vspace(大约)删除垂直空间,但它不可靠,因为它会随着文本大小的变化而变化。

\begin{absolutelynopagebreak}
\vspace{-1.3\baselineskip}
\begin{theorem}
Statement 006.
\end{theorem}
\vspace{-0.65\baselineskip}
\end{absolutelynopagebreak}

答案1

尝试这个:
在此处输入图片描述

\documentclass{article}
\usepackage{amsthm} % For theorem environments

\newtheorem{theorem}{Theorem}

\makeatletter
\newenvironment{absolutelynopagebreak}
  {\par\@nobreaktrue\nobreak\penalty0}
  {\par\@nobreakfalse}
\makeatother

\begin{document}

\begin{theorem}
Statement 001.
\end{theorem}

\begin{theorem}
Statement 002.
\end{theorem}

\begin{absolutelynopagebreak}
\begin{theorem}
Statement 003.
\end{theorem}
\end{absolutelynopagebreak}

\begin{theorem}
Statement 004.
\end{theorem}

\begin{theorem}
Statement 005.
\end{theorem}

\end{document}

环境使用\@nobreaktrue\@nobreakfalse来管理分页行为。这是一种更直接的方法,应该对自然间距的干扰较少。该\penalty0命令用于阻止分页,而无需插入额外空间。

相关内容