2

How can I use a Beamer Color, lets say the one given by \usebeamercolor[bg]{palette primary} as color name in order to be used in a \rowcolors command for example.

In the following MWE I would like to use something like beamercolor[bg]{palette primary} instead of lightgray in \rowcolors{1}{}{lightgray}:

\documentclass[xcolor=table]{beamer}
\usetheme{Warsaw}
\usecolortheme{seahorse}

\definecolor{lightgray}{gray}{0.9}

\begin{document}
\begin{frame}

\rowcolors{1}{}{lightgray}

\begin{tabular}{r|rrrrr}
  \hline
 & 1 & 2 & 3 & 4 & 5 \\
  \hline
1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
   \hline
\end{tabular}


\end{frame}
\end{document}

1 Answer 1

2

Following the comments at Getting the color from a beamer theme? you can use the Beamer color names in the same way as a regular color name if you first 'activate' them using \usebeamercolor. You can put this inside of a {} group so that the \usebeamercolor statement does not actually apply the color anywhere but it still makes the color name available for commands outside of the {} group.

MWE:

\documentclass[xcolor=table]{beamer}
\usetheme{Warsaw}
\usecolortheme{seahorse}

\definecolor{lightgray}{gray}{0.9}

\begin{document}
\begin{frame}{Title}

{\usebeamercolor[bg]{palette primary}}
\rowcolors{1}{}{palette primary.bg}

\begin{tabular}{r|rrrrr}
  \hline
 & 1 & 2 & 3 & 4 & 5 \\
  \hline
1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
   \hline
\end{tabular}


\end{frame}
\end{document}

Result:

enter image description here

Note that I added a frame title to the MWE, otherwise LaTeX thought that {\usebeamercolor[bg]{palette primary}} was the frame title, which does not make the color available - it needs to be inside of the frame.

1
  • That's just perfect! Thanks a lot! Just a comment, it seems that the "activation" with the \usebeamercolor[..]{..} command can be done in preambule (before the \begin{document} and so no need to put it between brackets {}. Thanks again !
    – zetyty
    Feb 11, 2022 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .