# Avoid page break after \item-followed-by-newline

My document has multiple occurrences of the code fragment

\item~\newline
\begin{center}
\includegraphics{...}
\end{center}
\item


and occasionally, the first item comes right at the end of a page, so the item label is separated from the figure. How can I avoid this? (I use this construct so as to get the item label above the figure instead of aligned with the figure's bottom, which is what happens by default).

-

\documentclass{article}
\makeatletter
\makeatother
\begin{document}
Here is some text. \par
\vspace{0.95\textheight}
\begin{itemize}
\item~\mynobreakpar
\begin{center} Here is an item \\line 2\end{center}
\end{itemize}
\end{document}


(Instead of center you can then also use \centering).

-

Since you mention "occasionally", you could just use \needspace{2\baselineskip}* before the item to require at least two \baselineskip space; if not, issue a \break. This is provided by the needspace package.

\documentclass{article}
\usepackage{needspace}% http://ctan.org/pkg/needspace
\begin{document}
Here is some text. \par
\vspace{​0.88\textheight}
\begin{itemize}
\item~\newline
Here is an item
\needspace{2\baselineskip}% Remove to see the effect
\item~\newline
Here is an item
\end{itemize}
\end{document}


* Technically, it might be more appropriate to use \needspace{\dimexpr\topsep+\baselineskip} for top-of-list items and \needspace{\dimexpr\itemsep+\baselineskip} for non-top items, for obvious reasons.

-
That works great for the one-offs (like fixing up the document at the very end). But is there an approach that will avoid the problem altogether? –  rogerl Dec 15 '11 at 23:35
You can patch \item using etoolbox. Add \usepackage{etoolbox} \preto\item{\needspace{2\baselineskip}} in your document preamble. Would that work? That would be general though for all lists (enumerate, itemize and description). –  Werner Dec 15 '11 at 23:42

You can avoid a page break at the line break with \nopagebreak. But there's also a problem in that center has an implicit page break. I'll probably burn in hell for using \centerline, but...

\item~\nopagebreak\\[-\baselineskip]
\centerline{\includegraphics{...}}

-
Why \centerline and not {\centering ... }? –  rogerl Dec 16 '11 at 1:49
I tried {\centering\includegraphics{...}\par}, but that also centered the bullet. To fix that, you'd need to change the first line to \item\nopagebreak\\[-\baselineskip]\par. –  rdhs Dec 16 '11 at 2:11