5

Why doesn't the following MWE change the color of the latter fill to red? How to fix?

Background: I am changing the structure color for my example frames and want all the tikzpictures within to use colors based on the structure color.

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}{My Default Structure Color Rectangle}
\begin{tikzpicture}
    \draw [fill=structure] rectangle (2,2);
\end{tikzpicture}
\end{frame}

\setbeamercolor{structure}{fg=red}

\begin{frame}{My Red Rectangle}
\begin{tikzpicture}
    \draw [fill=structure] rectangle (2,2);
\end{tikzpicture}
\end{frame}
\end{document}
Matti
  • 1,003
  • 2
  • 10
  • 24

1 Answers1

3

You have to set \usebeamercolor before actually use it. In addition you should specify .fg while using the color, i.e. structure.fg. This is because while setting \usebeamercolor you also have access to structure.bg, which is a different color.

The code:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
    \begin{frame}{My Default Structure Color Rectangle}
        \begin{tikzpicture}
        \draw [fill=structure] rectangle (2,2);
        \end{tikzpicture}
    \end{frame}

    \setbeamercolor{structure}{fg=red}

    \begin{frame}{My Red Rectangle}
    \usebeamercolor{structure}  
        \begin{tikzpicture}
        \draw [fill=structure.fg] rectangle (2,2);
        \draw (4,0) [fill=structure.bg] rectangle+ (2,2);
        \end{tikzpicture}
    \end{frame}
\end{document}

The result:

enter image description here