# Figure with minipage alignment issues [duplicate]

I have a figure block with 2 'minipage', each having a figure. When I typeset the document, the figure goes to the top of the page instead of being in the sub-section where I am defining it. The following is the code I am using to do this.

\begin{figure}
\centering
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[height=.4\linewidth]{sample.png}
\caption{Collection Definition}
\end{minipage}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[height=.4\linewidth]{tree.png}
\caption{Collection Result}
\end{minipage}
\end{figure}


## marked as duplicate by Red, Martin Schröder, henrique, Ingo, Andrew SwannOct 24 '13 at 12:21

• add \usepackage{flafter} – David Carlisle Oct 24 '13 at 10:30

You are missing the optional position specifier [htbp] for the figure environment.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\section{Some section}
\begin{figure}[htb]                    %% here
\centering
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[height=.4\linewidth]{example-image-a}
\caption{Collection Definition}
\end{minipage}
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[height=.4\linewidth]{example-image-b}
\caption{Collection Result}
\end{minipage}
\end{figure}
\lipsum
\end{document}


• @eddyrokr: h means possibly here, t means possible at the top and b is possibly at the bottom. if you put a ! in front ([!htb]), it becomes more compelling than a request (I want it here/top/bottom - a demand not a request ;-)). There is also p specifier meaning to put figure in a separate float only page. – user11232 Oct 24 '13 at 10:49