0

every time that i put a (figure) in latex, it appears in some random places rather than the place I actually write the code. for example, for the following code, it will be appeared at the beginning of the next page of the place that the code is placed in the code:

\begin{figure*}
\centering
\includegraphics[scale=0.5]{example.eps}
\caption{Figure}
\end{figure*}

what to do?

lonesome
  • 565
  • Are you using a document class in twocolumn mode? – Werner Jan 08 '15 at 05:51
  • 2
    Welcome to TeX.SE. If you want the figure placed exactly where you place it eliminate the figure environment. The figure environment is a floating environment so it is intended float. – Peter Grill Jan 08 '15 at 06:49
  • \begin{figure*} means "move this content to the top of a following page" so the behaviour you describe is exactly the intention of that markup. – David Carlisle Jan 08 '15 at 09:43
  • @Werner what kind of document class do u mean? – lonesome Jan 09 '15 at 02:56
  • @PeterGrill if i remove it, then how am I supposed to show a photo? – lonesome Jan 09 '15 at 03:20
  • @DavidCarlisle and whats your solution? – lonesome Jan 09 '15 at 03:20
  • Its \includegraphics that shows the image, not the figure environment. – Peter Grill Jan 09 '15 at 03:52
  • @user1064929: A solution will be forthcoming once you provide us with more details in terms of your document setup. As of now, it's really unclear how to precisely solve the problem, or it's a duplicate of the mentioned post. – Werner Jan 09 '15 at 05:43
  • @user1064929 graphics are positioned in exactly the same way as a letter x if you just use \includegraphics{..} or just use x it appears in natural order ifrom the source, if you use \begin{figure}x\end{figure} or \begin{figure}\includegraphics{..}\end{figure} then it is a float and will be positioned at a suitable place to get god page breaks. – David Carlisle Jan 09 '15 at 08:40
  • @DavidCarlisle but then how to add captions and so on? because if i remove the figure part, i cant use caption{} label{} and so on – lonesome Jan 11 '15 at 05:17
  • 1
    The main reason that conventionally figures have captions is that a (human or mechanical) typesetter traditionally will move a figure to a place convenient for the typesetter so you need to be able to give it context and reference it. So logically if you are just including an image it doesn't need a referencable caption you can just describe it in the adjacent text. However if you use the capt-of package (1 line of code:-) then you can use \captionof{figure}{my caption} anywhere. – David Carlisle Jan 11 '15 at 11:39

1 Answers1

2

Read the comment by @Peter Grill in the OP. As he said, the figure environment is a float. LaTeX will position wherever it think it's convenient. You can force it to put the figure in the place where you include it, with an option [placement specifier]

\begin{figure}[specifier]
...
\end{figure}

You can use "h" (without quotes) for here, "t" for top of the page, "b" for bottom of the page, "p" for a separate page and even "h!", with the exclamation mark overriding all placement rules and putting your figure where you include it, regardless of how bad it will look.

My advice: include your figures and mind their specific position after you're done with everything else. Try to not use " h" as specifier. Most stylistic rules consider than figures should always go at the top or bottom of the page, not on the center and rarely two figures in the same page or column. That's basically what LaTeX tries to do.

Good luck

phollox
  • 554
  • i used [h[ before and to be honest, it almost never put it "here" . but seems the answer is to use [!htbp] . at least worked for now – lonesome Jan 09 '15 at 03:22
  • Ok, if it works for you . I think that "h!" should be enough – phollox Jan 09 '15 at 19:11
  • I see. but there is another question . how can I place it like a two-column photo? I mean the reason I used figure* was for the fact I wanted to place it in both columns. but as it turned out that nature of * is to place the photo at top of next page, found it not useful. so how can I put it at top of same page but as a two-column photo? – lonesome Jan 11 '15 at 05:30
  • @user1064929 figure* always goes to the next page for technical reasons, but you can simply move it back in the source so that it comes at the top of the page that you need. – David Carlisle Jan 11 '15 at 11:42
  • 1
    @phollox !h is usually a bad idea, mostly latex will warn and change it to [!ht] to give itself a chance, but it's almost always best to include p in any optional float argument. – David Carlisle Jan 11 '15 at 11:43
  • @DavidCarlisle you still didnt tell me how to put it back?...oh do you mean I put the code one page before the place it should appear on top? – lonesome Jan 12 '15 at 02:14