Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 3 down vote accepted
\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).

share|improve this answer

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.

share|improve this answer
    
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{...}}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.