0

I've tried this in different occasions within the past year and I have always had the same problem. I go to the line of the Latex code where I want to insert my images using \begin{figure}, but the images appear before the content in the previous lines:

\lstinputlisting{q9_1_c.m}


\vspace*{5\baselineskip}

\begin{figure}[!tbp]
  \centering
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{diff_6}
    \caption{$\nu = 6$.}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{diff_7}
    \caption{$\nu = 7$}
 \end{minipage}
   \hfill
 \begin{minipage}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{diff_8}
\caption{$\nu = 8$}
 \end{minipage}
\end{figure}

produces a layout in which the images precede the code included using \lstinputlisting{}. This is not an issue if I just use \includegraphics, but I needed to put 3 images next to each other. Why doesn't this work?

  • Welcome to TeX SE! Because figure is an environment which tells LaTeX to 'float' the contents to the best location, where the best location is determined by LaTeX's algorithm. You can put the graphics next to one another without using a figure environment. Just don't put paragraph breaks between them. – cfr Oct 01 '14 at 02:51
  • Thanks! How can I also include captions without using the figure environment? – sodiumnitrate Oct 01 '14 at 02:55
  • 1
    See http://tex.stackexchange.com/questions/7210/label-and-caption-without-float. – cfr Oct 01 '14 at 02:59
  • 2
    Your figure go to the top of the page because you are using the t op option in figure. Change [!tpb] by just [bp] or [hbp]. BTW, \centering is superfluous here. BTW, may be you are searching for one figure with three subfigures? In this case use the subfig or subcaption packages instead of minipages. – Fran Oct 01 '14 at 04:45
  • BTW, it is safer user \linewidth that \textwidth. See what happen with this figure if you add twocolumn options to the document class, or if the figure is part of of a item in a list, for example. See http://tex.stackexchange.com/a/142709/11604 – Fran Oct 01 '14 at 04:58
  • The reason that typesetting systems move figures (and figures have referencable captions) is to avoid bad page breaks. If you do not float the figures you will get large spaces at page breaks, and really captions are not required as the image is then just part of the text flow (like an equation which similarly does not float, and is typically not captioned) – David Carlisle Oct 01 '14 at 11:30
  • The previously referenced solution is far more complicated than needed. Just use \captionof{figure}{yada yada yada} anywhere. It will then show up in the list of figures as well. – John Kormylo Oct 01 '14 at 23:03

0 Answers0