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.

I have a text, where pictures are interleaved with descriptions for them. And since pictures are quite big, sometimes picture moves to next page, but the description for it stays on the previous page, which is ugly.

The code:

Some description for the following image:
\begin{center}
  \includegraphics[width=\textwidth]{../path/to/image.png}
\end{center}

I tried using \nopagebreak, but LaTeX just ignored me. And using samepage also did not help - it started to pull the text from under the previous image down the page.

What can I do to keep the description and the image on the same page?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If you know the height of the image, you might try the needspace package and say \Needspace{the height you need} before the image.

share|improve this answer
    
Needspace looks good. But it is really scary - what if I change the size of an image and forget to update the \needspace declaration? –  Rogach Mar 28 '12 at 0:19
    
@Rogach, in that case, you might try David Carlisle's solution instead -- it's more robust. –  Ben Lerner Mar 28 '12 at 1:09
\noindent\begin{minipage}{\textwidth}
Some description for the following image:
\begin{center}
  \includegraphics[width=\textwidth]{../path/to/image.png}
\end{center}
\end{minipage}

makes an indivisible box that will never break.

share|improve this answer

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.