To start off, I know this is addressed in this question, but their solution breaks for me in a particular case so I'm looking for something better.
The minimum working example #1 is shown below. The idea here is to redefine the enumerate environment as a new environment called procedure
. The purpose of this new environment is to append some additional text to the end of every item in the environment. This works well, however, very often the appended text gets sent to another page if that particular item is near the page boundary.
The solution provided by the linked question above says to make the items into a minipage. This is done in MWE #2. This works fine to keep specific items together, but then those items will flow over the page! Inserting a \clearpage
or \newpage
before the specific items does nothing. My guess is that latex somehow doesn't know the size of the minipage items and thus cant' budget for their space properly.
Can anyone offer a resolution here? I'd just like the ability to keep an entire item in the procedure environment together and have it automatically push the entire item to the next page if it can't all fit at the end of the current page.
MWE #1
Code
\documentclass{article}
\usepackage{lipsum}
\def\initial{\par \vspace{2ex} Initial: \underline{\hspace{10em}}}
\let\olditem\item
\let\saveenumerate\enumerate
\let\saveendenumerate\endenumerate
\newenvironment{procedure}{%
\def\newitem{\initial\olditem}
\saveenumerate
\def\step{%
\let\step\newitem\olditem
}
}{%
\initial\saveendenumerate%
}
\begin{document}
\begin{procedure}
\step \lipsum[1]
\step \lipsum[2]
\step \lipsum[3]
\step \lipsum[4]
\step \lipsum[5]
\end{procedure}
\end{document}
Output
The automatically appended text on item #4 is on the next page! I want to keep it with item #4, even if that means pushing item #4 to the next page entirely.
MWE #2
Code
\documentclass{article}
\usepackage{lipsum}
\def\initial{\par \vspace{2ex} Initial: \underline{\hspace{10em}}}
\let\olditem\item
\let\saveenumerate\enumerate
\let\saveendenumerate\endenumerate
\newenvironment{procedure}{%
\def\newitem{\initial\olditem}
\saveenumerate
\let\closepage\relax
\def\step{%
\closepage
\let\step\newitem\olditem
\minipage[t]{\linewidth}
\let\closepage\endminipage
}
}{%
\initial\closepage\saveendenumerate%
}
\begin{document}
\begin{procedure}
\step \lipsum[1]
\step \lipsum[2]
\step \lipsum[3]
\step \lipsum[4]
\step \lipsum[5]
\step \lipsum[6]
\end{procedure}
\end{document}
Output
The items are kept together now, but item #6 flows past the edge of the page! This doesn't work for me either.