如何在 beamer 中插入 tikzpicture?

如何在 beamer 中插入 tikzpicture?

我想运行这张幻灯片beamer。我尝试了很多方法,但总是出现包冲突的错误。

\documentclass{beamer}

\usetheme{AnnArbor}
\usecolortheme{beaver}

\setbeamercolor*{palette tertiary}{use=structure,fg=black,bg=blue}

\mode<presentation>
\usepackage{setspace}
\usepackage{nicefrac}
\usepackage{xcolor}
\usepackage{float}
\usepackage{breqn}
\usepackage{tikz}
\usepackage{indentfirst}
\usepackage{bibentry} 
\usepackage{color}
\usetikzlibrary{matrix}
\usepackage{apacite}
\usepackage{color}
\usepackage{graphicx}
\usepackage{comment}
\usepackage{hyperref}
\usepackage {xcolor}
\usepackage{graphicx,epsfig,setspace,subfig,url,amsmath}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{array}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{enumerate}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{etex}
\usepackage[all]{xypic}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{bm}
\renewcommand{\familydefault}{\sfdefault}

% New packages


%\setbeamertemplate{itemize item}{\scriptsize\raise1.25pt\hbox{\donotcoloroutermaths$\blacktriangleright$}}
\setbeamertemplate{itemize subitem}{\tiny\raise1.5pt\hbox{\donotcoloroutermaths$\blacktriangleright$}}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
     \begin{frame}
    \begin{figure}[H]
    \tikzset{
      basic/.style  = {draw, text width=2cm, drop shadow,  rectangle},
      root/.style   = {basic, thin, align=center,
                   fill=gray!45 , text width=7em},
      level 2/.style = {basic, thin,align=center, fill=gray!30,
                   text width=7em},
      level 3/.style = {basic, thin, align=left, fill=gray!20, text width=7em, node distance = 40pt}
    }
    \begin{tikzpicture}[
      level 1/.style={sibling distance=40mm},
      edge from parent/.style={->,draw},
      >=latex]

    % root of the the initial tree, level 1
    \node[root] {BRD1 ($\alpha_{..},\beta_{..}$)}
    % The first level, as children of the initial tree
      child {node[level 2] (c1) {$(\alpha_{..},\beta_{i.})$}}
      child {node[level 2] (c2) {$ (\alpha_{.j},\beta_{..})$}}
      child {node[level 2] (c3) { $(\alpha_{..},\beta_{.j})$}}
      child {node[level 2] (c4) { $(\alpha_{i.},\beta_{..})$}};

    % The second level, relatively positioned nodes
    \begin{scope}[every node/.style={level 3}]
    \node [below of = c1, xshift=20pt] (c11) { $(\alpha_{i.},\beta_{i.})$};
    \node [below of = c11 ] (c12) {BRD9 $(\alpha_{.j},\beta_{i.})$};
    %\node [below of = c12] (c13) {$(\alpha_{..},\beta_{i.})$};

    \node [below of = c2, xshift=20pt] (c21) { $(\alpha_{.j},\beta_{.j})$};
    \node [below of = c21 ] (c22) {BRD9 $(\alpha_{.j},\beta_{i.})$};

    \node [below of = c3, xshift=20pt] (c31) { $(\alpha_{.j},\beta_{.j})$};
    \node [below of = c31 ] (c32) {BRD8 $(\alpha_{i.},\beta_{.j})$};

    \node [below of = c4, xshift=20pt] (c41) { $(\alpha_{i.},\beta_{i.})$};
    \node [below of = c41 ] (c42) { $(\alpha_{i.},\beta_{.j})$};

    %\node [below of = c2, yshift=-15pt, xshift=10pt] (c21) {Membership driven Re-Keying};
    %\node [below of = c21] (c22) {Time driven Re-Keying};

    %\node [below of = c3, xshift=15pt] (c31) {Ring-based Cooperation};
    %\node [below of = c31] (c32) {Hierarchical Cooperation};
    %\node [below of = c32] (c33) {Broadcast Cooperation};
    \end{scope}

    % lines from each level 1 node to every one of its "children"
    \foreach \value in {1,2}
      \draw[->] (c1.195) |- (c1\value.west);

    \foreach \value in {1,2}
      \draw[->] (c2.195) |- (c2\value.west);

    \foreach \value in {1,2}
      \draw[->] (c3.195) |- (c3\value.west);
    \foreach \value in {1,2}
      \draw[->] (c4.195) |- (c4\value.west);

    \end{tikzpicture}\\
    %\caption{Schematic Presentation of BRD models~\citep{Jansen05} } 
    \end{figure}
    \end{frame}
\end{document}

答案1

您的tikz代码需要该shadows库,因此您应该添加

\usetikzlibrary{shadows}

到你的序言。错误消息 produce 表示 thetdrop shadow未知。drop shadow在 中查找pgfmanual,例如通过texdoc pgfmanualtexdoc tikz显示它是shadows库的一部分。

现在您需要调整图表的大小...编辑:我给出了一种方法来减少您拥有的固定水平参数的数量:

示例输出

\documentclass{beamer}

\usetheme{AnnArbor}
\usecolortheme{beaver}

\usepackage{tikz}
\usetikzlibrary{shadows}

\begin{document}

\begin{frame}
  \begin{figure}[H]
    \tikzset{
      basic/.style  = {draw, text width=5em, drop shadow,  rectangle},
      root/.style   = {basic, thin, align=center,
                   fill=gray!45 , text width=5em},
      level 2/.style = {basic, thin,align=center, fill=gray!30,
                   text width=5em},
      level 3/.style = {basic, thin, align=left, fill=gray!20, text
      width=5em, node distance = 40pt} 
    }
    \begin{tikzpicture}[
      level 1/.style={sibling distance=30mm},
      edge from parent/.style={->,draw},
      >=latex]

    % root of the the initial tree, level 1
    \node[root] {BRD1 ($\alpha_{..},\beta_{..}$)}
    % The first level, as children of the initial tree
      child {node[level 2] (c1) {$(\alpha_{..},\beta_{i.})$}}
      child {node[level 2] (c2) {$ (\alpha_{.j},\beta_{..})$}}
      child {node[level 2] (c3) { $(\alpha_{..},\beta_{.j})$}}
      child {node[level 2] (c4) { $(\alpha_{i.},\beta_{..})$}};

    % The second level, relatively positioned nodes
    \begin{scope}[every node/.style={level 3}]
    \node [below of = c1, xshift=10pt] (c11) { $(\alpha_{i.},\beta_{i.})$};
    \node [below of = c11 ] (c12) {BRD9 $(\alpha_{.j},\beta_{i.})$};
    %\node [below of = c12] (c13) {$(\alpha_{..},\beta_{i.})$};

    \node [below of = c2, xshift=10pt] (c21) { $(\alpha_{.j},\beta_{.j})$};
    \node [below of = c21 ] (c22) {BRD9 $(\alpha_{.j},\beta_{i.})$};

    \node [below of = c3, xshift=10pt] (c31) { $(\alpha_{.j},\beta_{.j})$};
    \node [below of = c31 ] (c32) {BRD8 $(\alpha_{i.},\beta_{.j})$};

    \node [below of = c4, xshift=10pt] (c41) { $(\alpha_{i.},\beta_{i.})$};
    \node [below of = c41 ] (c42) { $(\alpha_{i.},\beta_{.j})$};

    %\node [below of = c2, yshift=-15pt, xshift=10pt] (c21) {Membership driven Re-Keying};
    %\node [below of = c21] (c22) {Time driven Re-Keying};

    %\node [below of = c3, xshift=15pt] (c31) {Ring-based Cooperation};
    %\node [below of = c31] (c32) {Hierarchical Cooperation};
    %\node [below of = c32] (c33) {Broadcast Cooperation};
    \end{scope}

    % lines from each level 1 node to every one of its "children"
    \foreach \value in {1,2}
      \draw[->] (c1.195) |- (c1\value.west);

    \foreach \value in {1,2}
      \draw[->] (c2.195) |- (c2\value.west);

    \foreach \value in {1,2}
      \draw[->] (c3.195) |- (c3\value.west);
    \foreach \value in {1,2}
      \draw[->] (c4.195) |- (c4\value.west);

    \end{tikzpicture}\\
    %\caption{Schematic Presentation of BRD models~\citep{Jansen05} } 
    \end{figure}
    \end{frame}
\end{document}

相关内容