Consider the following code, copied almost verbatim from this answer, except that two calls to \lipsum,
\lipsum[1-4]
\lipsum[5][1-10]
have been added inside the document's body.
\documentclass{article}
\usepackage{lipsum}
\newenvironment{signenv}[1]{%
\par
\smallskip
\noindent\hrulefill\ %
\begin{picture}(20,20)(0,0)
\put(10,0){\makebox(0,0){#1}}
\put(0,0){\line(1,1){10}}
\put(0,0){\line(1,-1){10}}
\put(20,0){\line(-1,1){10}}
\put(20,0){\line(-1,-1){10}}
\end{picture}\ %
\hrulefill
\par
\bigskip}
{\par\medskip\noindent\hrulefill\par\smallskip}
\begin{document}
\lipsum[1-4]
\lipsum[5][1-10]
\begin{signenv}{A}
\lipsum[1]
\end{signenv}
\end{document}
The resulting PDF file has two pages, as follows.
As can be seen, the top line drawn by the signenv environment appears on a different page than the paragraph contained inside the environment. Similarly, if you replace the first two calls to \lipsum by
\lipsum[1-3]
\lipsum[4][1]
the bottom line drawn by the signenv environment appears on a different page than the paragraph contained inside the environment.
How can I arrange it so that both the top and the bottom lines of the signenv environment will always appear on the same page as the text inside the environment?


\bigskipafter the top line nor the\medskipbefore the bottom line? Is there a\noskipthat works with\nopagebreak? Does the\nopagebreakwork before\par? – Evan Aad Jul 19 '21 at 14:07\lipsum[1]that's inside thesignenvenvironment is inserted into atheoremenvironment:\begin{signenv}{A}\begin{theorem}\lipsum[1]\end{theorem}\end{signenv}. Could you please look into it? (Of course, you need to add\newtheorem{theorem}{Theorem}to the preamble.) – Evan Aad Jul 19 '21 at 14:25\bigskip\csname @afterheading\endcsname– Ulrike Fischer Jul 19 '21 at 14:53