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}
1

1 Answer 1

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}

You must log in to answer this question.

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