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.
Best Answer
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 twominipage
s is2\textwidth
, which is wider than\textwidth
.There are a few things that we can do to fix this:
\end{minipage}
and the second\begin{minipage}...
width
argument of eachminipage
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%
after the first\end{minipage}
which removes the little bit of horizontal space that is automatically inserted by theminipage
environment.Referring to this line of your code:
This will refer to the current
linewidth
, i.e, the width of the currentminipage
in which it resides. If we make eachminipage
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 theminipage
, 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.
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 thefigure
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 aBernoulli
equation , you might label itfig:bernoulli
.