23

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}
1
  • 1
    Welcome to TeX.SE. Enclosing it in a minipage is one option. That is if you want the entire enumerated list on one page. If you want a particular item completely on one page, you could use the resume feature from the enumitem package. Oct 12, 2012 at 21:21

3 Answers 3

15

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}
0
5

Be sure to add such adjustments only when finalizing your document.

In the following example document, the first line of the second item would be typeset on page one.

\documentclass{article}
\usepackage{lipsum}

\begin{document}

\lipsum[1-4]

\begin{enumerate}

\item \lipsum*[2]

\begingroup\interlinepenalty=10000
\item \lipsum*[3]

\endgroup

\end{enumerate}

\end{document}

Don't forget the empty line (or \par) before \endgroup.

2
  • Thanks. Your example works but for some reason it doesn't seem to work within my more complicated document. I'll try to come up with an example I can post.
    – rmp251
    Oct 12, 2012 at 21:54
  • @user432311 Have you nested lists?
    – egreg
    Oct 12, 2012 at 22:17
5

This worked for me:

\begin{enumerate}
\begin{minipage}{\textwidth} \item Blah blah blah ... \end{minipage}
\begin{minipage}{\textwidth} \item Blah blah blah ... \end{minipage}
\end{enumerate}
3
  • minipage needs a width as mandatory argument.
    – esdd
    Sep 19, 2017 at 19:42
  • This shouldn’t work! The fact that it (apparently, in simple situations) does looks like a LaTeX bug! Indeed, \@item issues \global\@inlabeltrue, and I can’t remember—or understand—off the top of my head the rationale behind that \global.
    – GuM
    Sep 27, 2017 at 16:01
  • Hmm. I'm not fluent in TeX enough to tell you why or how, I just know that it works great for me. It's simple and does everything I want it to. I went back and looked at the code, and this (with the {\textwidth}) is exactly what I am using. Unfortunately, I can't share the code because the document is an exam. Sep 28, 2017 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .