[Tex/LaTex] Avoid page break after \item-followed-by-newline

listspage-breaking

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).

Best Answer

\documentclass{article}
\makeatletter
 \newcommand\mynobreakpar{\par\nobreak\@afterheading}
\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).