Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent page break within \item in latex document

I have a long document consisting of an enumeration. Each item consists of several lines, and possibly also includes other elements such as graphics and lists. The document type requires that each of these items appears on a single page, with no page break within item. Unused white space at the bottom of the page is acceptable.

Here is an example

\documentclass[a5paper,12pt]{article}
\usepackage{blindtext}

\begin{document}
\begin{enumerate}
  \item \blindtext
  \item \blindtext % don't break this apart
  \item very long text here 
\end{enumerate}
\end{document}

I know of solutions with the samepage environment, and also with minipage. The problem is that I can't wrap the individual \items into these environments, which I would need.

needspace works, but then I need to determine the vertical extent of each item manually (at least that is what I think).

like image 734
user52366 Avatar asked Dec 15 '17 12:12

user52366


People also ask

How do you stop page breaks in LaTeX?

The \nopagebreak command prevents LaTeX form breaking the current page at the point of the command. With the optional argument, number, you can convert the \nopagebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

How do I reduce space before LaTeX?

You have to do it manually: \kern-\parskip\begin{itemize} then your \items and then \end{itemize}\kern-\parskip.


2 Answers

What I did in the end is use the enumitem package and break up the enumeration into parts which are in minipages:

\documentclass[a5paper,12pt]{article}
\usepackage{blindtext}
\usepackage{enumitem}           % modified itemize

\begin{document}
\begin{minipage}{\linewidth}
\begin{enumerate}[series=task,start=1,leftmargin=*,resume]
  \item \blindtext
\end{enumerate}
\end{minipage}

\begin{minipage}{\linewidth}
  \begin{enumerate}[resume*=task]
     \item \blindtext
  \end{enumerate}
\end{minipage}

\end{document}

I'd prefer something less complicated, but at least it worked without manual pagination.

like image 58
user52366 Avatar answered Oct 16 '22 13:10

user52366


You can issue a \clearpage with each \item via the following automation:

enter image description here

\documentclass[a5paper,12pt]{article}

\usepackage{blindtext}

\let\oldenumerate\enumerate% Store \begin{enumerate} in \begin{oldenumerate}
\let\endoldenumerate\endenumerate% Store \end{enumerate} in \end{oldenumerate}
\renewenvironment{enumerate}
  {\let\olditem\item% Store \item in \olditem
   \renewcommand{\item}{\clearpage\olditem}% Update \item
   \oldenumerate}% \begin{enumerate}
  {\endoldenumerate}% \end{enumerate}

\begin{document}

\begin{enumerate}
  \item \blindtext
  \item \blindtext % don't break this apart
  \item very long text here 
\end{enumerate}

\end{document}

The above code updates the enumerate environment in a way that changes the \item code to be equivalent to \clearpage\item instead. This ensures that each \item will start on a new page, possibly leaving blank space at the bottom.

like image 20
Werner Avatar answered Oct 16 '22 12:10

Werner