71

I am trying to put two figures next to each other. However, it is not working. Here is my code:

\begin{figure}[h]
\centering

\begin{minipage}{1.0\textwidth}
\centering
\includegraphics[width=0.3\linewidth, height=0.15\textheight]{prob1_6_2}
\caption{$dt=0.1$}
\label{fig:prob1_6_2}
\end{minipage}

\begin{minipage}{1.0\textwidth}
\centering
\includegraphics[width=0.3\linewidth, height=0.15\textheight]{prob1_6_1}
\caption{$dt =$}
\label{fig:prob1_6_1}
\end{minipage}

\end{figure}

In my preamble I have \usepackage{minipage}. But it hasn't worked. And yes, I have searched through other posts.

5
  • 4
    You have a break (empty line and whitespace) in between the minipage environments. Remove the empty line and place % after the first \end{minipage}. Also, you cannot place two minipages side-by-side if each one is the width of the typeblock. No extra package is required for minipage; it is a standard environment. Feb 2, 2014 at 20:34
  • 1
    @PaulGessler Okay, thank you. What should I change the width to?
    – Mack
    Feb 2, 2014 at 20:52
  • 1
    If you want the two minipages to span the width of the text area, the sum of their widths should be 1.0\textwidth. The specific values depend on the size of the figures and how you'd like them arranged. Check the link in @cmhughes comment for more details. Feb 2, 2014 at 21:03
  • also don't use [h] on its own it makes it highly likely the float goes to the end of the document latex will usually warn and change it to [ht] to give itself a chance , but best to include p as well: [thp] Feb 2, 2014 at 21:20
  • Also, no line break between the minipage environments.
    – Jason
    May 5, 2018 at 16:52

2 Answers 2

82

Blank lines tell LaTeX to start a new paragraph, which is one of the reasons that your code puts the figures on their own lines; the other reason is that the sum of the width of your two minipages is 2\textwidth, which is wider than \textwidth.

There are a few things that we can do to fix this:

  • remove the blank line between the first \end{minipage} and the second \begin{minipage}...
  • change the width argument of each minipage so that the combined width is less than or equal to \textwidth; of course, if you'd prefer to overflow the page margins, then you can crank it up higher
  • add a % after the first \end{minipage} which removes the little bit of horizontal space that is automatically inserted by the minipage environment.

Referring to this line of your code:

\includegraphics[width=0.3\linewidth, height=0.15\textheight]{prob1_6_2}

This will refer to the current linewidth, i.e, the width of the current minipage in which it resides. If we make each minipage have a width of .5\textwidth, then the width of this graphic will actually be .15\textwidth wide. Adjust as you see fit- typically, I specify the width of the minipage, and then prefer to use \includegraphics[width=\textwidth...

Finally, there are some concerns about using \begin{figure}[h]. Float placement has been discussed in great detail at the following links (in order of recommended reading- the last one is epic):

Here is a complete (modified) version of your code that implements the changes described above.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}[!htb]
    \centering
    \begin{minipage}{.5\textwidth}
        \centering
        \includegraphics[width=0.3\linewidth, height=0.15\textheight]{prob1_6_2}
        \caption{$dt=0.1$}
        \label{fig:prob1_6_2}
    \end{minipage}%
    \begin{minipage}{0.5\textwidth}
        \centering
        \includegraphics[width=0.3\linewidth, height=0.15\textheight]{prob1_6_1}
        \caption{$dt =$}
        \label{fig:prob1_6_1}
    \end{minipage}
\end{figure}
\end{document}

For further options about putting figures side by side, have a look at LaTeX figures side by side and the links within- there are a lot of options available.

My final comment is to consider using descriptive labels- using \label{fig:prob1_6_1} is ok, but it doesn't tell you much about what the figure actually shows you. This may not matter when you're writing the document and you are intimately familiar with it, but if you come back to it at a later time, you might wish for more details; for example, if the figure shows solution to a Bernoulli equation , you might label it fig:bernoulli.

6
  • 2
    Not sure what you mean by "add a % after the first \end{minipage} which removes the little bit of horizontal space that is automatically inserted by the minipage environment." Adding that % simply removes the end-line character that LaTeX would convert to a space. The minipage doesn't automatically insert any space on its own, regardless of what follows \end{minipage}.
    – Dan
    Feb 3, 2014 at 5:00
  • 1
    @Dan thanks for the clarification- I'll updated later today
    – cmhughes
    Feb 3, 2014 at 16:42
  • Is there any possibilities of arranging the figure anywhere we want.???
    – David
    Feb 12, 2015 at 17:39
  • @David I'm afraid I don't understand your question... could you clarify?
    – cmhughes
    Feb 12, 2015 at 18:28
  • @cmhughes In reference to Davids question, I am having the same issue. I would like the figure to show up precisely there it is in my TeX document. This figure shows up at the top of the next page. Thanks.
    – user90401
    Feb 5, 2016 at 5:40
-1

This problem may be due to larger subcaption text. Reduce the length of subcaption and your problem will be solved.

1
  • 2
    It should work with different sized captions as well (I, for one, do it rather often). Mar 6, 2019 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .