0

This is my first time being here. The site is such an asset. Asking this only because I couldn't get it done. Question. I want to insert two (may be three) images with captions for each. I was referring this: This is my code for that particular frame:

\usepackage{graphicx}
\usepackage{float}

    \begin{frame}
    \begin{tabular}{ccc}
    \subfloat[caption]{\includegraphics[width = 2in]{image1.jpg}} &
    \subfloat[caption]{\includegraphics[width = 2in]{image2.jpg}} 
    \end{tabular}
    \end{frame}

I get an error saying: \subfloat outside float. I'm using the online .tex editor Overleaf.

Any help is much appreciated.

2

In a presentation often have little sense numbered subcaptions and the superfluous "Figure:" statement. As the issue with all of this is solved in another answer, my suggestion is not use at all figure floats, captions or any related package:

mwe

\documentclass{beamer}
\begin{document}
\begin{frame}\centering
\begin{columns}
\begin{column}{.3\linewidth}\centering
\includegraphics[width=\linewidth]{example-image-a}\par 
The image A
\end{column}
\begin{column}{.3\linewidth}\centering
\includegraphics[width=\linewidth]{example-image-b}\par 
The image B
\end{column}
\begin{column}{.3\linewidth}\centering
\includegraphics[width=\linewidth]{example-image-c}\par 
The image C
\end{column}
\end{columns}
\bigskip
The main caption
\end{frame}
\end{document}
  • Why not a tabular? – egreg Apr 2 '17 at 8:35
  • @egreg This morning I was not quite "tabulator". That's all. :D – Fran Apr 2 '17 at 18:01
0

The solution is to use figure outside (it's a float and it's for images):

\begin{frame}
\begin{figure}[h] %<-- NEW
\begin{tabular}{ccc}
\subfloat[caption]{\includegraphics[width = 2in]{image1.jpg}} &
\subfloat[caption]{\includegraphics[width = 2in]{image2.jpg}} 
\end{tabular}
\end{figure} %<-- NEW
\end{frame}

If you'd like to have many options with your captions probably you should switch to the package subcaption (uses caption) and this approach:

\begin{frame}
   \begin{figure}
        \begin{subfigure}{.45\textwidth}
            \centering
            \includegraphics[width = \linewidth]{example-image-a.jpg}
            \caption{Caption}
        \end{subfigure}\hfill
        \begin{subfigure}{.45\textwidth}
            \centering
            \includegraphics[width = \linewidth]{example-image-b.jpg}
            \caption{Caption}
        \end{subfigure}
        \caption{Test}
    \end{figure}
\end{frame}
  • @ TeXnician, it worked. Thank you very much. Could you please tell me how to adjust the dimensions of the images ? – Eureka Apr 1 '17 at 17:30
  • @Eureka There is a parameter width you already issued and adjusted. – TeXnician Apr 1 '17 at 17:32
  • the way it appears now is one image is taller than the other and two are closer to each other. That's what I want to change. – Eureka Apr 1 '17 at 17:33
  • @Eureka Please edit your question and post a screenshot of what you want to adjust. – TeXnician Apr 1 '17 at 17:34
  • if you use, for example \includegraphics[width = \linewidth]{example-image-b.jpg}, than \centering its position inside subfigure has no sense ... and can/should be omitted :) – Zarko Apr 1 '17 at 21:52

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.