0

I like the idea of absolutelynopagebreak environment and I'd like to use it for wrapping theorem-like environments when needed (without modifying those environments). It does work, but the problem is that it creates additional vertical space (before and after).

Is there a way to fix this?

\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}

I was able to remove vertical space using vspace (approximately), but it's not reliable since it changes when text size changes.

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

1 Answers1

-1

Try this:
enter image description here

\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}

The environment uses \@nobreaktrue and \@nobreakfalse to manage the page breaking behavior. This is a more direct approach and should interfere less with the natural spacing. The \penalty0 command is used to discourage page breaks without inserting additional space.