# How can I force an image and its caption to be on the same page?

I am using the caption package, now I have one problem: In one case an image is placed at the bottom of one page, while its caption is placed on the top of the following page. In this case I would prefer the image to be also moved to the next page.

Actually my LaTeX code looks like this:

\begin{flushleft}
\includegraphics{sample.png}
\captionof{figure}{the caption}
\label{figure:sample}
\end{flushleft}

Is there some way to tell LaTeX that the graphic and the caption shall be seen as one unit and shall never be split up over 2 pages?

-
Why don't you use the figure environment? –  Martin Schröder Nov 19 '11 at 22:25

I would suggest to improve Stefan's answer by putting minipage inside figure environment. So image + caption can still be a floating object:

\begin{figure}
\begin{minipage}{\textwidth}
\includegraphics{sample.png}
\caption{the caption}
\label{figure:sample}
\end{minipage}
\end{figure}
-
You don't need a minipage inside the figure environment. They all become a single entity. –  percusse Aug 11 at 12:57