8

I'm trying to insert an image in LaTeX with some text around:

Here is our image:
\begin{figure}[h!]
    \centering
    \includegraphics[width=0.5\textwidth]{idefA0.jpg}
    \caption{IDEF0}
\end{figure}
Here is some text!

I'd like to insert image and 'Here is some image' on the same page, but when i'm trying to compile pdf I get: Warning! !h changed to !ht and places an image on the next page, and here is some text goes right after Here is some image

What's wrong?

4
  • Hi. There is specialized place for TeX questions - tex.stackexchange.com
    – Paul Lysak
    Mar 24 '11 at 16:16
  • possible duplicate of Insert image in latex
    – Jake
    Apr 4 '11 at 13:52
  • possible duplicate of Force figure placement in text
    – Caramdir
    Apr 4 '11 at 16:02
  • The answer by Matthias Vallentin nicely explains how to solve the problem using the figure environment. But you could also include an image by using \includegraphics in a center environment if you don't need or want the power of the figure environment. That would give you absolute control about the placement but you would have to give up the \caption as well. Apr 4 '11 at 17:59
17

LaTeX creates a float if you put includegraphics inside a figure environment. Floats are containers for objects that cannot be broken across page boundaries. By using figure, you're essentially telling the LaTeX compiler "please put the picture where you think it fits best."

To force a picture appearing at the exact location where it is in the source code, you can do either of the following:

  1. Use the H specifier for the figure environment. This requires \usepackage{float}.

  2. Don't wrap \includegraphics into a figure environment if you just want the plain image, without caption and other extras.

Example for the first option:

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{idefA0.jpg}
\caption{IDEF0}
\end{figure} 

You find more about floats here: http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions.

This exact problem is already covered in more depth at: Force figure placement in text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy