[Tex/LaTex] Page breaks within enumerated list

#enumeratelistspage-breaking

I'm writing a document with lots of numbered items, and I would like each of those items to be contained on a single page (rather than split across two pages). Is there a way to do this? samepage doesn't seem to work.

For example, if the following two items were too big to fit on the same page, I would like item 2 to move to the next page:

\begin{enumerate}

\item Blah blah blah ...
...

\item More babbling ...
...

\end{enumerate}

Best Answer

To ensure that an entire \item's text is on the same page (assuming of course that it will fit on the page), you can adapt the solution I used to Replace \item with \MyItem to box each list member with an mdframed, to instead place each \item within a minipage.

Here is a normal enumerate environment where item (c) is split across a page:

enter image description here

and using the MyEnumerate environment we get item (c) on a new page since it does not fit on the previous page.

enter image description here

Notes:

  • An \addvspace{\baselineskip} has been added in between the minipage to resolve the issue with vertical spacing issue that was in an earlier version.

  • The geometry package was used only to adjust the paper height to show that the MyEnumerate actually moves the list member to a new page if it does not fit.

Code:

\documentclass{article}
\usepackage{etoolbox}% for toggles
\usepackage{enumitem}

\usepackage[paperheight=5.8cm]{geometry}

\newcommand{\TextA}{%
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
        Sed accumsan hendrerit velit, vitae ultrices sapien porta nec.  
}%
\newcommand{\TextB}{%
        Duis blandit tempus placerat. 
        Nulla vitae erat ante. Nulla facilisi. 
        Aliquam tristique interdum suscipit. 
        Duis posuere orci vel velit suscipit in porttitor purus eleifend. 
}%
    
%  https://tex.stackexchange.com/questions/43002/how-to-preserve-the-same-parskip-in-minipage
\newlength{\currentparskip}
    
% https://tex.stackexchange.com/questions/56435/replace-item-with-myitem-to-box-each-list-member-with-an-mdframed
\newcommand{\MyItem}{\item}

\newtoggle{FirstItem}%
\toggletrue{FirstItem}

\toggletrue{FirstItem}%
\newenvironment{MyEnumerate}[1][]{%
    \renewcommand{\MyItem}{%
        \iftoggle{FirstItem}{%
            \global\togglefalse{FirstItem}
            \setlength{\currentparskip}{\parskip}% save the value
            %--------- start new minipage
            \par\addvspace{\baselineskip}\noindent
            \begin{minipage}{\textwidth}%
            \setlength{\parskip}{\currentparskip}% restore the value
            \begin{enumerate}[#1,series=MySeries]%
        }{%
            \end{enumerate}%
            \end{minipage}%
            %--------- end previous minipage and start new one
            \par\addvspace{\baselineskip}\noindent
            \begin{minipage}{\textwidth}%
            \setlength{\parskip}{\currentparskip}% restore the value
            \begin{enumerate}[#1,resume*=MySeries]%
        }%
        \item\mbox{}%
    }%
}{%
    \end{enumerate}%
    \end{minipage}% --------- end last minipage
    \global\toggletrue{FirstItem}%
}%

\begin{document}\noindent
\textbf{enumerate:}
\begin{enumerate}[label={(\alph*)}]
    \item \TextA
    \item \TextB
    \item \TextA\TextB
\end{enumerate}
%
\clearpage
\textbf{MyEnumerate:}
\begin{MyEnumerate}[label={(\alph*)}]
    \MyItem \TextA
    \MyItem \TextB
    \MyItem \TextA\TextB
    \MyItem \TextB
\end{MyEnumerate}
\end{document}
Related Question