3

I am defining a corporate design beamer template.

Actually, I have defined some given colors in the beamercolorthemeCD.sty file. (Next step will be, to define some font templates via beamerfontthemeCD.sty. Maybe I will face the same problem, as with the colors?)

I am using tikzpictures to place the different CD elements onto my slides. To make it most efficient and simple, I defined some global TikZ styles by \tikzset...

Now I want to combine the beamer template definitions with the TikZ styles, e.g. I want to use a special color given in the beamercolorthemeCD.sty on some TikZ drawn elements using the \tikzset defining a style.

This definition does not work:

%% Define the color, 
\setbeamercolor{dark decoration}{fg=black}

%% Use that color in this TikZ style
\tikzset{%
   dark/.style={%
      line width=\rulerwidth,
      color={\usebeamercolor{dark decoration}},
   }%
}%

LaTeX gives an error

Missing \endcsname inserted.

and also

Paragraph ended before \XC@col@rlet was complete.

I found a similiar question here, stating, that you can use the color of the actual beamer template.

But in my case, the decoration elements are used in different locations (e.g. headline, footline and other templates), where different foreground and background colors are used. (The decoration elements should not change the color in the different templates/environments.)

Also: at the time, when the TikZ styles are defined, there is no actual template in effect, so just saying color=fg, as the solving answer suggests, does not work in my case.

Is there a way, to globally define the TikZ style colors using a beamer color template?

Here is an MWE to play with

\documentclass{beamer}
\usepackage{tikz}

\title{Some ordinary title}
\author{I. T. Sme, A. Gain}
\date{Later On}

\setbeamercolor{dark decoration}{fg=black}
\setbeamercolor{light decoration}{fg=grey}

\tikzset{%
  dark/.style={%
    line width=1pt,
    % This doesn't work :(
    color={\usebeamercolor{dark decoration}},
  }%
}%
      
\begin{document}
  \begin{frame}
    \begin{tikzpicture}
      \draw[dark] (0,0) -- (1,1);
    \end{tikzpicture}
  \end{frame}

\end{document}

1 Answer 1

1

You have to use the color at least once to have it available in xcolor format. This works:

\documentclass{beamer}
\usepackage{tikz}

\title{Some ordinary title}
\author{I. T. Sme, A. Gain}
\date{Later On}

\setbeamercolor{dark decoration}{fg=black}
\setbeamercolor{light decoration}{fg=grey}

\tikzset{%
  dark/.style={%
    line width=1pt,
    % This doesn't work :( unless you use the color before!
    color=dark decoration.fg,
  }%
}%
      
\begin{document}
  \begin{frame}
  
  {\usebeamercolor[fg]{dark decoration}}
    \begin{tikzpicture}
      \draw[dark] (0,0) -- (1,1);
    \end{tikzpicture}
  \end{frame}

\end{document}

I am on a cellphone now, and it's too painful to check what happens exactly - the blank line after the \begin{frame} is necessary. Tomorrow I'll adjust it...

2
  • Wow. Easy solution. THANK YOU.
    – Jan
    Commented Jun 8, 2021 at 4:59
  • I used a \AtBeginDocument{\usebeamercolor{dark decoration}\tkizset{... and it worked charmingly! Even without blank lines at \begin{frame}.
    – Jan
    Commented Jun 8, 2021 at 5:28

You must log in to answer this question.

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