4

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.

signenv across a page break with the upper line separated

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.

signenv across a page break with the lower line separated.

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?

Evan Aad
  • 11,066

1 Answers1

9

as I commented under the original code, you can add \nopagebreak

\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 \nopagebreak \bigskip} {\par\nopagebreak\medskip\noindent\hrulefill\par\smallskip}

\begin{document}

\lipsum[1-4]

\lipsum[5][1-10]

\begin{signenv}{A} \lipsum[1] \end{signenv}

\end{document}

David Carlisle
  • 757,742