# Trouble placing images side by side in beamer

I need to place a couple of images side by side (horizontally) in a presentation I'm doing with beamer, so I looked around and inserted the following code (sugested by this post):

\documentclass{beamer}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{frame}

\begin{figure}
\centering

\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image1}
\caption{A subfigure}
\end{minipage}
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{image2}
\caption{A subfigure}
\end{minipage}

\caption{A figure with two subfigures}
\end{figure}

\end{frame}

\end{document}


But the images appear one over the other (vertically). I tried both approaches suggested in the aforementioned post but I get the same result. What can I be doing wrong and how can I fix it?

• Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. And use \usepackage[demo]{graphicx} to illustrate the figure's problem, instead of using grafo.png. – adn Nov 29 '13 at 13:08
• you have a paragraph break (blank line) between your images. You want them in the same line, so in the same paragraph, and since you have used .5\textwidth you have no room for any space so you need \end{minipage}\begin{minipage}... in the middle – David Carlisle Nov 29 '13 at 13:15
• I removed the blank line but I still get the same result. – Victor Gil Nov 29 '13 at 13:19

The minipage environment adds a small piece of horizontal space after it, so if you use

    ...
\begin{minipage}{.5\textwidth}
...
\end{minipage}%
\begin{minipage}{.5\textwidth}
...


then you get the desired result- here's a complete MWE.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-a}
\caption{A subfigure}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-b}
\caption{A subfigure}
\end{minipage}
\caption{A figure with two subfigures}
\end{figure}
\end{frame}
\end{document}


0.5\textwidth is too much. Use 0.45. Also the minipage environment should stick together as shown below.

\documentclass[]{beamer}
\begin{document}
\begin{frame}
\begin{figure}
\centering
\begin{minipage}{.45\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-a}
\caption{A subfigure}
\end{minipage}
\begin{minipage}{.45\textwidth}
\centering
\includegraphics[width=.4\linewidth]{example-image-b}
\caption{A subfigure}
\end{minipage}
\caption{A figure with two subfigures}
\end{figure}
\end{frame}
\end{document}

• Glad I can help. You can use scale=0.45 instead of 0.4\linewidth to make the picture fuller. But this is your choice. – Jesse Nov 29 '13 at 13:25