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?
figureis 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 afigure environment. Just don't put paragraph breaks between them. – cfr Oct 01 '14 at 02:51figure environment? – sodiumnitrate Oct 01 '14 at 02:55top option infigure. Change[!tpb]by just[bp]or[hbp]. BTW,\centeringis superfluous here. BTW, may be you are searching for one figure with three subfigures? In this case use thesubfigorsubcaptionpackages instead of minipages. – Fran Oct 01 '14 at 04:45\linewidththat\textwidth. See what happen with this figure if you addtwocolumnoptions 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