1

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 Swann Oct 24 '13 at 12:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

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}

enter image description here

A must read: Frank's answer to this question.

  • Awesome! Thanks a lot. What does [htb] stand for? – eddyrokr Oct 24 '13 at 10:45
  • 1
    @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
  • @eddyrokr Read this excellent answer for details: tex.stackexchange.com/a/39020/11232 – user11232 Oct 24 '13 at 10:52
  • That was helpful :) – eddyrokr Oct 24 '13 at 10:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.