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?
Best Answer
LaTeX creates a float if you put
includegraphics
inside afigure
environment. Floats are containers for objects that cannot be broken across page boundaries. By usingfigure
, 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:
Use the
H
specifier for the figure environment. This requires\usepackage{float}
.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:
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.