7

I am trying to use tikzset with an argument in a beamer document, and I am having an error I do not understand.

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\begin{frame}{My try} 
\begin{tikzpicture}
    \tikzset{boite/.style={draw=#1}}
    \node[boite=red] {The text} ;
\end{tikzpicture}
\end{frame} 

\end{document}

The error I get with this code is

! Illegal parameter number in definition of \test.
<to be read again> 
                   1
l.10     \end{tikzpicture}

Note that the exact same code in an article works like a charm:

\documentclass{article}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
    \tikzset{boite/.style={draw=#1}}
    \node[boite=red] {The text} ;
\end{tikzpicture}
\end{document}
Bruno
  • 1,975
  • 4
    This is the same issue given in http://tex.stackexchange.com/questions/118781/finding-the-depth-of-nesting-in-a-macro-call You can take out the setting to your preamble or put [fragile] option to the frame – percusse Jun 15 '13 at 15:36

1 Answers1

9

Percusse's comment solves this issue, and I just adapt from this question. There are (at least) three solutions.

Either the frame can be given the option [fragile], or replace #1 by ####1 (see the the linked question for details on why four #s are needed), or simply put the tikzset in the preamble.

A working solution:

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\begin{frame}{My try} 
\begin{tikzpicture}
    \tikzset{boite/.style={draw=####1}}
    \node[boite=red] {The text} ;
\end{tikzpicture}
\end{frame} 

\end{document}
Bruno
  • 1,975