[Tex/LaTex] Custom caption for tables in `beamer`

beamercaptionsnamingtables

I’m using the caption package, to name tables in beamer. \caption{Name} automatically provides Table: Name output. I would like to change the word “Table” to a custom caption, but also to be able to have a different caption for different tables. E.g.:

\documentclass[pdf,xcolor=table]{beamer}
\setbeamercovered{highly dynamic}
\usepackage{caption}
\mode<presentation>{}
\begin{document}
\begin{frame}
\begin{table}[]
  \centering
  \caption{Name 1.}
  \begin{tabular}{|l|l|}
  \hline
   &  \\ \hline
   &  \\ \hline
  \end{tabular}
  \end{table}

\begin{table}[]
  \centering
  \caption{Name 2.}
  \begin{tabular}{|l|l|}
  \hline
  &  \\ \hline
  \end{tabular}
\end{table}

\end{frame}
\end{document}

Above the first table gets a caption “Table: Name 1.” and the second “Table: Name 2.”. I want to be able to call the first one “Random Caption: Name 1.”, and second “Different Random Caption: Name 2.”. Can I change this caption for different tables independently?

Best Answer

There is no need to use the caption package for this as you can just redefine \tablename to suit your needs:

enter image description here

\documentclass{beamer}

\begin{document}

\begin{frame}

  \begin{table}
    \centering
    \renewcommand{\tablename}{Random Caption}
    \caption{Name 1.}
  \end{table}

  \begin{table}
    \centering
    \renewcommand{\tablename}{Different Random Caption}
    \caption{Name 2.}
  \end{table}

\end{frame}

\end{document}

The redefinition is localized to the table environment, like with all scoping within the \begin ... \end group.