# Subcaption with Beamer

I am trying to use subcaption with beamer, but I get a series of error messages concerning subcaption.sty when I attempt to do so. This doesn't happen in the article document class. Here is a MWE

\documentclass{beamer}

\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{frame}
\begin{figure}
\begin{subfigure}[b]{.45\linewidth}
\centering
\caption{First subfigure}
\label{fig:a}
\textcolor{blue}{\rule{3cm}{3cm}}
\end{subfigure}\hfill
\begin{subfigure}[b]{.45\linewidth}
\centering
\caption{Second subfigure}
\label{fig:b}
\textcolor{blue}{\rule{3cm}{3cm}}
\end{subfigure}\    \caption{A figure}\label{fig:1}
\end{figure}
\end{frame}
\end{document}

Package caption Warning: \caption will not be redefined since it's already
(caption)                redefined by a document class or package which is
(caption)                unknown to the caption package.
See the caption package documentation for explanation.

! Package caption Error: The subcaption' package does not work correctly
(caption)                in compatibility mode.

See the caption package documentation for explanation.
Type  H <return>  for immediate help.
...

l.7 \begin{document}

?
! Emergency stop.
...

l.7 \begin{document}


Any tips?

-
In general don't use floats with figures because they can't shift to other slides (would be awkward anyway) and you also don't need captions as nobody needs to know the number of the figure. Mention somewhere in the frame and that would be much more sensible. – percusse Jul 26 '13 at 16:11
@percusse No; beamer internally deactivates the floating mechanism, so figure and table don't produce floating objects; one can still use those environment in case one wants to use \caption. – Gonzalo Medina Jul 26 '13 at 18:34
@GonzaloMedina Oh I didn't know that. – percusse Jul 26 '13 at 19:12
Your example document works fine here (TeXlive 2013). What error messages are you getting? Is updating your TeX distribution an option? – Axel Sommerfeldt Jul 27 '13 at 5:37
There's been new developments with the caption package and now subcaption and beamer are compatible. I added a ermark about this in my updated answer and thought that you might be interested too. – Gonzalo Medina Sep 26 '15 at 15:17

## Update caption version 2015/09/17 v3.3-111

Now, since version version 2015/09/17 v3.3-111 of the caption package, subcaption and beamer are again compatible so the error in the question won't appear and subcaption can be used with beamer.

## Answer for older versions of caption

The error message is produced since when subcaption gets loaded the compatibility boolean option for caption is found to be true, and subcaption.sty contains the lines:

\caption@AtBeginDocument{\caption@ifcompatibility{%
\caption@Error{%
The subcaption' package does not work correctly\MessageBreak
in compatibility mode}}{}}


which trigger the error. You can prevent this error by using the compatibility=false option for caption (and keep your fingers crossed (see below)), as in the following exmaple:

\documentclass{beamer}
\usepackage[compatibility=false]{caption}
\usepackage{subcaption}

\begin{document}
\begin{frame}
\begin{figure}
\begin{subfigure}[b]{.45\linewidth}
\centering
\caption{First subfigure}
\label{fig:a}
\textcolor{blue}{\rule{3cm}{3cm}}
\end{subfigure}\hfill
\begin{subfigure}[b]{.45\linewidth}
\centering
\caption{Second subfigure}
\label{fig:b}
\textcolor{blue}{\rule{3cm}{3cm}}
\end{subfigure}\    \caption{A figure}\label{fig:1}
\end{figure}
\end{frame}
\end{document}


However, this might produce undesired results in beamer's captions; in fact, with the above document you get the warning

Package caption Warning: Forced redefinition of \caption since the (caption) unsupported(!) package option compatibility=false' (caption) was given. See the caption package documentation for explanation.

The caption package documentation also warns against using this option:

But please note that using this option is neither recommended nor supported since unwanted side-effects or even errors could occur afterwards. (For that reason you will get a warning about this.)

If captions and subcaptions are really required for a presentation, I think a better option with beamer is to use subfig with its caption=false option instead of caption/subcaption:

\documentclass{beamer}
\usepackage[caption=false]{subfig}

\begin{document}

\begin{frame}
\begin{figure}
\centering
\subfloat[Second subfigure\label{fig:b}]{\textcolor{blue}{\rule{3cm}{3cm}}}
\caption{A figure}
\label{fig:1}
\end{figure}
\end{frame}

\end{document}


## Remark

It's a very common misconception to believe that the figure and table environments shouldn't be used in beamer (the alleged reason is something like "they might produce objects that will float away"). This is not true; beamer internally deactivates flotation, so it is perfectly safe to use figure and table if you really need to provide captions in a presentation.

Section 12.6 Figures and Tables of the beamer manual clearly explains this:

You can use the standard LaTeX environments figure and table much the same way you would normally use them. However, any placement specification will be ignored. Figures and tables are immediately inserted where the environments start. If there are too many of them to fit on the frame, you must manually split them among additional frames or use the allowframebreaks option.

-
Isn't a floating environment within a beamer frame a Latex sin? – pluton Apr 3 '14 at 3:14
@pluton No; beamer internally deactivates flotation. It keeps the figure and table environments (but, as I said, suppressing the flotation) just to give the possibility to use \caption. Another thing is if you really need captions in your presentations. It is a common mistake to believe that figure (or table) inside beamer might produce flotation to a different slide. – Gonzalo Medina Apr 3 '14 at 3:16
@pluton Please read Section 12.6 Figures and Tables of the beamer` manual. – Gonzalo Medina Apr 3 '14 at 3:20