2

Possible Duplicate:
How to influence the position of float environments like figure and table in LaTeX?

sometimes im in trouble with my images. Because if there is no space on one page, the images is getting printed on the next page. Thats fine, but if I write a text after the image on the pdf the text is before the image.

Something like this:

\begin{figure}[htb]
\centering
\includegraphics*[width=1\textwidth]{myimage.pdf}
\caption{\em Description}
\label{fig:myimage}
\end{figure}

\hspace{0pt}
\\

MyText. But this text appears sometimes before the image and not after how it should be.

I saw this question. People are explaining h,t,b but its not helping me. How can I solve this problem? Thank you

Edit: I could solve this problem with adding a lot of new lines, something like this:

\begin{figure}[htb]
\centering
\includegraphics*[width=1\textwidth]{myimage.pdf}
\caption{\em Description}
\label{fig:myimage}
\end{figure}

\hspace{0pt}
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\

Now its fine.

But this cannot be the solution...

David Carlisle
  • 757,742
Klaus
  • 21
  • 5
    Basically, LaTeX handles positioning of float environments like figure by itself. To understand how they are positioned, you should read this post: http://tex.stackexchange.com/a/39020/16873 – Corentin Oct 02 '12 at 12:06
  • the figure is a floating environment which means that latex can move it to a suitable point in the document to achieve good page breaks as is traditional in publishing. If you do not want the figure to move the easiest thing is to load the float package and change htb to H which means PUT IT HERE then latex will not move it – David Carlisle Oct 02 '12 at 12:08
  • @DavidCarlisle ah now I get it. So h != H, because I was trying h an it did not change anything. Basically "H" is always the best thing I can do right? Dont understand why would I use the other one, with htb Im just getting in trouble. – Klaus Oct 02 '12 at 12:14
  • 3
    Also, don't use \ to force vertical white space and don't use the two letter font commands like \em which are only for compatibility with the pre-1993 LaTeX 2.09 system. It is best to avoid formatting command in captions at all, the class should determine the style used for captions (the caption package can help you define that) – David Carlisle Oct 02 '12 at 12:15
  • 4
    No!!!! H is almost always a REALLY BAD IDEA (I was the first one to implement H so I can say that with some authority:-) figures are big unbreakable blobs and if you include one mid page with H then the only thing latex can do is leave that page short with a big white gap and move everything to the next page. Real printers would never do that that is why articles have figures as referenced items so that the printer can put them in a good place and the text can refer to it by reference. – David Carlisle Oct 02 '12 at 12:17
  • You should design your text in a way that it doesn't matter if it is before or after the figure. You can always use the reference mechanism (\label and \ref) unambiguously refer to the figure. This shouldn't confuse any reader since it's common practice in articles and books. – cgnieder Oct 02 '12 at 12:24
  • if you know the graphic fits in the location where it's input, it's not necessary to wrap it in a figure environment, and there are packages to provide an alternate method of referenceable captioning. (you may have to adjust the vertical spacing around it.) – barbara beeton Oct 02 '12 at 12:29

1 Answers1

2

Summing up the comments.

If you really need to stop LaTeX moving the figure then use the float package and

\begin{figure}[H]

Note that using H is more or less equivalent to not using a figure at all and just placing the graphic and caption in a full width minipage. (The caption-of package will allow you to caption such non-floating environments).

However it is almost always better to allow the figure to move and use the \label \ref mechanism to refer to it by number in the text, that allows LaTeX to find much better page breaks. To achieve this do not use an optional argument at all, or if you want to allow figures mid-page if they will fit then use

\begin{figure}[htbp]

Always include at least p in such an optional argument otherwise you increase the chance that LaTeX can not find anywhere to place the figure. The full details of the figure placement (perhaps more details than you want initially) are in Frank Mittelbach's description.

David Carlisle
  • 757,742