10

I want to place captions at right/left side of pictures in a beamer presentation. However, the following code does not work due to incompatibilities between beamer and floatrow.

\documentclass{beamer}
\setbeamertemplate{caption}{\insertcaption}

\usepackage{floatrow}

\begin{document}

\begin{frame}
    \begin{figure}
        \floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,bottom},capbesidewidth=0.4\textwidth}}]{figure}[\FBwidth]
        {\caption{Example image}\label{fig:example}}
        {\includegraphics[width=0.5\textwidth]{example-image}}
        %\includegraphics[width=0.5\textwidth]{example-image}
        %\caption{Example image}
        %\label{fig:example}
    \end{figure}
\end{frame}

\end{document}
11

Here is a solution using a columns environment:

\documentclass{beamer}
\setbeamertemplate{caption}{\insertcaption}

\begin{document}
\begin{frame}
    \begin{figure}
      \begin{columns}
        \column{.6\linewidth}
        \includegraphics[width=\textwidth]{example-image}
        \column{.3\linewidth}
        \caption{Example image}
        \label{fig:example right}
      \end{columns}
    \end{figure}
\end{frame}

\begin{frame}
    \begin{figure}
      \begin{columns}
        \column{.3\linewidth}
        \caption{Example image}
        \label{fig:example left}
        \column{.6\linewidth}
        \includegraphics[width=\textwidth]{example-image}
      \end{columns}
    \end{figure}
\end{frame}
\end{document}

enter image description here

enter image description here

Edit

Here, I define a new command (\figurewithcaptionatside) with 3 parameters (first parameter is optional):

  1. the options : caption position (vertical position: c, t orb), caption on the left, caption on the right, caption width, image width,

  2. the material to make the caption,

  3. the material to make the figure.

I use pgfkeys to manage the options.

Usage:

\begin{figure}
  \figurewithcaptionatside
  [caption position=t,caption on the left]
  {\caption{Example image with left caption}\label{fig:example left}}
  {\includegraphics[width=\textwidth]{example-image}}
\end{figure}

The complete code:

\documentclass{beamer}

\makeatletter
\newif\ifcaptionsideisleft
\pgfset{
  fwcas@/.is family,
  fwcas@,
  caption position/.is choice,
  caption position/c/.code={
    \def\fwcas@captionposition{c}\def\fwcas@imageposition{c}
  },
  caption position/b/.code={
    \def\fwcas@captionposition{b}\def\fwcas@imageposition{b}
  },
  caption position/t/.code={
    \def\fwcas@captionposition{T}\def\fwcas@imageposition{T}
  },
  caption left side@/.is if=captionsideisleft,
  caption on the left/.style={caption left side@=true},
  caption on the right/.style={caption left side@=false},
  caption width/.code={
    \pgfmathsetmacro\fwcas@captionwidth{#1}
  },
  image width/.code={
    \pgfmathsetmacro\fwcas@imagewidth{#1}
  },
  every figurewithcaptionatside/.style={
    caption position=c,
    caption on the left,
    caption width=.3\linewidth,
    image width=.7\linewidth,
  },
}
\newcommand\figurewithcaptionatside[3][]{
  \pgfset{fwcas@,every figurewithcaptionatside,#1}
  \ifcaptionsideisleft
  \begin{columns}
    \column[\fwcas@captionposition]{\fwcas@captionwidth pt}
    #2
    \column[\fwcas@imageposition]{\fwcas@imagewidth pt}
    #3
  \end{columns}
  \else
  \begin{columns}
    \column[\fwcas@imageposition]{\fwcas@imagewidth pt}
    #3
    \column[\fwcas@captionposition]{\fwcas@captionwidth pt}
    #2
  \end{columns}
  \fi
}
\makeatother

\setbeamertemplate{caption}{\insertcaption}
\begin{document}
\begin{frame}
    \begin{figure}
      \figurewithcaptionatside
      {\caption{Example image with default value}\label{fig:example}}
      {\includegraphics[width=\textwidth]{example-image}}
    \end{figure}
\end{frame}

\begin{frame}
    \begin{figure}
      \figurewithcaptionatside
      [caption position=t,caption on the left,
      caption width=.5\linewidth,
      image width=.5\linewidth,
      ]
      {\caption{Example image with left caption}\label{fig:example left}}
      {\includegraphics[width=\textwidth]{example-image}}
    \end{figure}
\end{frame}

\begin{frame}
    \begin{figure}
      \figurewithcaptionatside
      [caption on the right,caption position=b]
      {\caption{Example image with right caption}\label{fig:example right}}
      {\includegraphics[width=\textwidth]{example-image}}
    \end{figure}
\end{frame}
\end{document}
  • I hope there is a solution using the same approach as floatrow. Nevertheless, this solution is useful because I can specify the vertical alignment, like \begin{columns}[b] [c] [T]. – cacamailg Nov 12 '14 at 22:33
  • @cacamailg I edited my answer to define a new command with some options... but floatrow is too big to redefine all its features in this answer! – Paul Gaborit Nov 12 '14 at 23:58
  • Yes you are right about floatrow. Nevertheless, the solution that you provided using the pgf macros does the job very well. Maybe it can be generically applied to "floats", I mean, also include tables. – cacamailg Nov 13 '14 at 0:27
  • not working if you already are within \begin{columns}\begin{column} {\begin{minipage}[t] .... – OD IUM Nov 17 '16 at 16:32
  • @ODIUM You can use nested columns but not in minipage... – Paul Gaborit Nov 17 '16 at 17:11

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.