beamer 框架内的 tikz 图片

beamer 框架内的 tikz 图片

我试图把tikz将官方页面中的代码beamer放入frame并出现此错误:

/home/.../file.tex:100: Illegal parameter number in definition of \test.
<to be read again> 
               1
l.100 \end{tikzpicture}`

但如果我把它放在外面,它frame会编译并创建一个新的框架,里面有这张图片,但有一些绝对错误的待处理(这张图片在的左上角frame

我怎样才能将此图像放入frame并进行适当的对齐(就像我放入文本时所具有的对齐方式一样frame

例如:

% Red-black tree
% Author: Madit
\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}

此代码给出了我上面描述的错误。如果我删除行

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

它可以工作,但对齐不正确。如果我删除

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

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

它也可以编译,无需任何样式,但位于具有适当对齐的框架内

答案1

使用\begin{frame}[fragile]....

相关内容