0

After reading some related question on how to insert an image into a TeX file I tried to do the following:


    \documentclass[11pt,a4paper]{report}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{graphicx}
    \begin{document}
    \section*{a section}
    \subsection*{a subsection}
    some text\
    \begin{figure}
    \centering
    \includegraphics[width=0.7\linewidth]{vagabon}
    \caption[]{an image}
    \label{fig:vagabon}
    \end{figure}\
    some other text
    \end{document}

but the output was: enter image description here

with the image before the sections, and not in between the 2 lines of text. why is that? and what's the proper way to insert an image in the middle of a paragraph?

  • 1
    Since you have it as a figure, it acts like a float and LaTeX will decide where is the most appropriate position for it. Hence, try \begin{figure}[!h] – azetina Jun 10 '14 at 16:35
  • 1
    This behaviour is by intention. Placing the figures (and tables) to their best place makes the /article/report/book much more readable. You can read more about the mechanism and how to tingle it in Franks answer -> How to influence the position of float environments like figure and table in LaTeX? – Johannes_B Jun 10 '14 at 16:38
  • @Johannes: thanks for the link, it provides an awesome explanation, I'll read it carefully and see if I can place the floats where I want them to be –  Jun 10 '14 at 16:46
  • @azetina: is there an alternative to having it as a figure? I tried this way because it was suggested in other SE questions –  Jun 10 '14 at 16:47
  • Do you need the \caption? – Torbjørn T. Jun 10 '14 at 17:04
  • @Torbjørn: it'd be nice to have it, but if there's a much easier way dropping it then I can do without it! –  Jun 10 '14 at 17:08
  • 1
    You can add \usepackage{capt-of} and then use \noindent\begin{minipage}{\linewidth}\includegraphics{..}\captionof{figure}{Some fig.\label{stuff}}\end{minipage}. Another option is to add \usepackage{float} and use the H float specifier, i.e. \begin{figure}[H], which disables floating. See also http://tex.stackexchange.com/questions/2275/keeping-tables-figures-close-to-where-they-are-mentioned – Torbjørn T. Jun 10 '14 at 17:13
  • @TorbjørnT.: using \figure[H] doesn't render the image, however using \figure[!h] as suggested by azetina works perfectly! –  Jun 10 '14 at 17:23
  • Not sure why it happens, but I think it moved to the next page. – Torbjørn T. Jun 10 '14 at 17:27
  • @TorbjørnT.: you're right, it is moved to the following page, I didn't notice it –  Jun 10 '14 at 17:28
  • Note that if you don't need the caption, you can just say \includegraphics[...]{...} and LaTeX will put the graphic wherever you've said to put it. (This does mean it matters where you say to put it, of course!) – cfr Jun 10 '14 at 23:59
  • [H] is an undefined option so just prevents the figure being placed anywhere so it goes to the end of the document. If you have a 2014 release and use package fixltx2e then you get an error message for undefined options. To define [H] meaning "here: do not float" you need the float package. – David Carlisle Aug 20 '14 at 10:29

0 Answers0