10

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
  • 1
    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
7

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}
5

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

enter image description here

Change your minipage to 0.45\textwidth

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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