3

beamer currently is incompatible with the caption package (as described here). I would like to define an additional command that works like the \caption* command of that package, i.e. typesets the caption without label and without entry in the list of tables/figures, but has the same formatting as the regular \caption-command. Important: I do still need the normal \caption command, so I cannot just globally redefine \setbeamertemplate{caption}

I am thinking about something along the lines of

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{caption}

\begin{document}
\begin{frame}{Some title}
  \begin{table}
    \begin{tabular}{cc}
      A & B \\
      C & D \\
    \end{tabular}
    \caption{Some numbered Table and its description. Even more and more and more text.}
  \end{table}

  \begin{table}
    \begin{tabular}{cc}
      A & B \\
      C & D \\
    \end{tabular}
  \caption*{Some unnumbered Table and its description. Even more and more and more text.}
  \end{table}
\end{frame}
\end{document}
  • Please add a small document to your question illustrating the problem. Then people can copy-paste-compile and experiment to find a solution, making it much easier to help and reducing the chances that an answer won't work for you. – cfr Aug 20 '15 at 13:08
  • @cfr I added a minimum non-working example, but I don't think that will be helpful as the problem is caused by a bug in caption (as pointed out by Joseph Wright) and I am looking for a different approach not involving that package. – jpfeifer Aug 20 '15 at 13:25
  • Do you have to call it \caption* ? All it does is write a caption without using or incrementing the float counter. The center environment will do that. – John Kormylo Aug 20 '15 at 13:55
  • @JohnKormylo The center environment will center it, but the default \caption in beamer will be left-aligned. Of course, I could manually make them similar. But the goal is to inherit the formatting from the original \caption command – jpfeifer Aug 20 '15 at 14:26
  • That's not what I see when I run your MWE (with \caption* removed). Anyway, you can test for the beamer class and use different definitions based on context. – John Kormylo Aug 20 '15 at 14:38
3

Here's one way to do it; \caption* inherits the same formatting as \caption (in particular, it has the same skips above and below and the single line feature):

enter image description here

The code:

\documentclass{beamer}
\usepackage{letltxmacro}
\usepackage{xparse}

\LetLtxMacro\oldcaption\caption

\makeatletter
\RenewDocumentCommand\caption{som}{
  \IfBooleanTF{#1}
    {
      \setbeamertemplate{caption label separator}[none]
      \def\insertcaptionname{}%
      \def\insertcaptionnumber{}%
      \def\insertcaption{#3}%
      \nobreak\vskip\abovecaptionskip\nobreak
      \sbox\@tempboxa{\usebeamertemplate**{caption}}%
      \ifdim \wd\@tempboxa >\hsize
        \usebeamertemplate**{caption}\par
      \else
      \global \@minipagefalse
        \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
      \fi
      \nobreak\vskip\belowcaptionskip\nobreak
    }
    {\oldcaption[#2]{#3}}
}
\makeatother

\newcommand\TestTable{%
    \begin{tabular}{cc}
      A & B \\
    \end{tabular}%
}

\begin{document}

\begin{frame}{Some title}

\begin{table}
\TestTable
\caption{Some numbered Table and its description. Even more and more and more text.}
\end{table}

\begin{table}
\TestTable
\caption*{Some unnumbered Table and its description. Even more and more and more text.}
\end{table}

\begin{table}
\TestTable
\caption{Some numbered Table}
\end{table}

\begin{table}
\TestTable
\caption*{Some unnumbered Table}
\end{table}

\end{frame}

\end{document}
|improve this answer|||||

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.