18

So I am trying to insert a functioning tikz image into a beamer project and it keeps giving me an error.

\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning}
\begin{document}
\begin{frame}{Examples}
\begin{center}
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1},minimum size=20pt,scale=.8,
every node/.style={transform shape}] % If you want to scale the picture insert ``scale=
(something), every node/.style={transform shape}'' Ex:[level/.style={sibling 
distance=60mm/#1},minimum size=20pt,scale=.8, every node/.style={transform shape}] would 
scale to 80% of original size
\node [circle,draw] (z){\textbf{$u$}}
  child {node [circle,draw,fill=black,text=white] (a) {\textbf{$v$}}
    child {node [circle,draw,fill=black,text=white] (c) {}}
    child {node [circle,draw] (d) {}
    }
  }
  child {node [circle,draw,fill=black,text=white] (b) {\textbf{$w$}}
    child {node [circle,draw,fill=black,text=white] (e) {}}
     child {node [circle,draw] (f) {}}
  };
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

The error I keep getting is:

./SDN Presentation.tex:61: Illegal parameter number in definition of \iterate.
<to be read again> 
                   1
l.61 \end{frame}

If I delete the /#1 at the beginning of the picture I get an image though not the one I am looking for. Not sure how to fix this issue since the code works for the amsart document class.

Bradley
  • 181

1 Answers1

23

You need to pass the fragile option to the frame environment to stop beamer trying to parse things it shouldn't.

\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning}
\begin{document}
\begin{frame}[fragile]{Examples}
\begin{center}
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1},minimum size=20pt,scale=.8,
every node/.style={transform shape}] % If you want to scale the picture insert ``scale= (something), every node/.style={transform shape}'' Ex:[level/.style={sibling distance=60mm/#1},minimum size=20pt,scale=.8, every node/.style={transform shape}] would scale to 80% of original size
\node [circle,draw] (z){\textbf{$u$}}
  child {node [circle,draw,fill=black,text=white] (a) {\textbf{$v$}}
    child {node [circle,draw,fill=black,text=white] (c) {}}
    child {node [circle,draw] (d) {}
    }
  }
  child {node [circle,draw,fill=black,text=white] (b) {\textbf{$w$}}
    child {node [circle,draw,fill=black,text=white] (e) {}}
     child {node [circle,draw] (f) {}}
  };
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

fragile tree

cfr
  • 198,882
  • Bro, I was losing my mind trying to solve a related problem with tikz and beamer and this [fragile] command solved all the problems. Thanks! – Powder Jan 30 '24 at 02:40