[Tex/LaTex] The best way to place two plots side by side

graphicsminipageplot

I am wondering did I use the right code, because the plots are not placed right in the Latex. Any better idea?

\documentclass[12pt]{report}
\usepackage{graphicx}
\begin{document}

\begin{figure}[ht!]
  \centering
\begin{minipage}[b]{0.4\textwidth}
\includegraphics[width=4.0in, height=2.7in] {temp.png}
\caption{Plot of hourly temperature from 2012-01-01 00:00 to 2016-06-13 23:00.} 
\end{minipage}
\hfill
\begin{minipage}[b]{0.4\textwidth}
  \includegraphics[width=2.7in, height=2.7in]{LRtemp.png}
 \caption{Linear relationship between demand and temperature}
\end{minipage}
\end{figure}

\end{document}

enter image description here

Best Answer

Some comments and observations, in no particular order:

  • The instruction \centering has no effect as the two minipage environments are separated by \hfill. Just omit \centering.

  • It may be more straightforward to set the widths of the two minipages to an absolute size, say, 4in and 2.7in, respectively, and then set the widths of the graphics to \linewidth.

  • A side-benefit of assigning absolute widths to the minipages and relative widths to the included graphics is that the widths of the captions and graphics will coincide -- something that's decidedly not the case in the screenshot you posted.

enter image description here

\documentclass[12pt]{report}
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\usepackage[margin=.5in,letterpaper]{geometry} % set page block parameters
\begin{document}
\setcounter{chapter}{2} % just for this example...
\setcounter{figure}{10}

\begin{figure}[ht!]
\begin{minipage}[b]{4in}
    \includegraphics[width=\linewidth, height=2.7in] {temp.png}
    \caption{Plot of hourly temperature from 2012-01-01 00:00 to 2016-06-13 23:00} 
\end{minipage}
\hfill
\begin{minipage}[b]{2.7in}
    \includegraphics[width=\linewidth, height=2.7in]{LRtemp.png}
    \caption{Linear relationship between demand and temperature}
\end{minipage}
\end{figure}
\end{document}