# tikz picture inside beamer frame

I was trying to put this code from tikz official page into a beamer's frame and got this error:

/home/.../file.tex:100: Illegal parameter number in definition of \test.
1
l.100 \end{tikzpicture}


But if I put this outside the frame it compiles and makes a new frame with this picture inside it but with some absolutely wrong pending (this picture is in the top-left corner of the frame)

How can I put this image inside the frame with a proper aligment (just like the one which does the text have when I put it in frame)

For example:

% Red-black tree
\documentclass[12pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows}

\tikzset{
treenode/.style = {align=center, inner sep=0pt, text centered,
font=\sffamily},
arn_n/.style = {treenode, circle, white, font=\sffamily\bfseries,     draw=black,
fill=black, text width=1.5em},% arbre rouge noir, noeud noir
arn_r/.style = {treenode, circle, red, draw=red,
text width=1.5em, very thick},% arbre rouge noir, noeud rouge
arn_x/.style = {treenode, rectangle, draw=black,
minimum width=0.5em, minimum height=0.5em}% arbre rouge noir, nil
}

\begin{document}
\begin{frame}{}
\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance =     5cm/#1,
level distance = 1.5cm}]
\node [arn_n] {33}
child{ node [arn_r] {15}
child{ node [arn_n] {10}
child{ node [arn_r] {5} edge from parent node[above     left]
{$x$}} %for a named pointer
child{ node [arn_x] {}}
}
child{ node [arn_n] {20}
child{ node [arn_r] {18}}
child{ node [arn_x] {}}
}
}
child{ node [arn_r] {47}
child{ node [arn_n] {38}
child{ node [arn_r] {36}}
child{ node [arn_r] {39}}
}
child{ node [arn_n] {51}
child{ node [arn_r] {49}}
child{ node [arn_x] {}}
}
}
;
\end{tikzpicture}
\end{frame}
\end{document}


This code give's an error I descripted above. If I delete lines

\begin{frame}{}
\end{frame}


It will work but not with a proper aligment. And if I delete

[->,>=stealth',level/.style={sibling distance = 5cm/#1, level distance = 1.5cm}]


in

\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 5cm/#1, level distance = 1.5cm}]


It will also compile with no styling but inside a frame with a proper aligment

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 22 '15 at 21:53
• @ChristianHupfer thanks for your tip! I've updated my question with some code – PepeHands May 22 '15 at 22:05
• Use \begin{frame}[fragile] – Ulrike Fischer May 22 '15 at 22:24
• @UlrikeFischer this worked, thanks a lot! Please, could you write this as an answer and I'm going to accept it. – PepeHands May 22 '15 at 22:58

Use \begin{frame}[fragile]....`