Beamer 与 Tikz 图表

Beamer 与 Tikz 图表

下列的我的问题是,我现在需要使用 Beamer 做一个演示文稿。

如果您查看下面的图,箭头上有一些值,即 p1、1-p1、... 我想先放置图形结构,然后按下箭头键时逐个显示值。
\pause在节点前面写入不起作用,那太简单了。 我不知道如何实现它,有人帮忙吗?

\documentclass{beamer}

\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\usepackage[english]{babel}
\usepackage{amsmath}

\begin{document}
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
                thick,main node/.style={rectangle,draw,font=\sffamily\Large    \bfseries}]  

\node[main node] (1) {1};
\node[main node] (2) [below = of 1] {2};
\node[main node] (3) [below = of 2] {3};
\node[main node,draw = none] (4) [right = 2in of 1] {$\varnothing$};
\node[main node,draw = none] (5) [right = 2in of 2] {$\varnothing$};
\node[main node,draw = none] (6) [right = 2in of 3] {$\varnothing$};

\path[every node/.style={font=\sffamily\small}]
(1) edge node [left] {$p_1$} (2)
    edge node [above] {$1-p_1$} (4)
(2) edge node [left] {$p_2$} (3)
    edge node [above] {$1-p_2$} (5)
(3)   edge node [above] {$1-p_3$} (6);
\path[draw,every node/.style={font=\sffamily\small}]
(3.west) -- ([xshift=-2cm]3.west) -- ([xshift=-2cm]1.west) node [midway,left] {$p_3$} -- (1.west); 
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案1

您可以使用visible on样式(参见思维导图 tikzpicture 在 beamer 中 (逐步显示))。下面代码中使用了这个,但还有一些其他选项,由马修·林冈克劳迪奥·菲安德里诺奎伯比尔贝尔或者贡萨洛·梅迪纳仅列举其中几个。

\documentclass{beamer}

\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\usepackage[english]{babel}
\usepackage{amsmath}

\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}

\begin{document}
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
                thick,main node/.style={rectangle,draw,font=\sffamily\Large    \bfseries}]  

\node[main node] (1) {1};
\node[main node] (2) [below = of 1] {2};
\node[main node] (3) [below = of 2] {3};
\node[main node,draw = none] (4) [right = 2in of 1] {$\varnothing$};
\node[main node,draw = none] (5) [right = 2in of 2] {$\varnothing$};
\node[main node,draw = none] (6) [right = 2in of 3] {$\varnothing$};

\path[every node/.style={font=\sffamily\small}]
(1) edge node [left, visible on=<2->] {$p_1$} (2)
    edge node [above, visible on=<2->] {$1-p_1$} (4)
(2) edge node [left, visible on=<3->] {$p_2$} (3)
    edge node [above, visible on=<3->] {$1-p_2$} (5)
(3)   edge node [above, visible on=<4->] {$1-p_3$} (6);
\path[draw,every node/.style={font=\sffamily\small}]
(3.west) -- ([xshift=-2cm]3.west) -- ([xshift=-2cm]1.west) node [midway,left, visible on=<4->] {$p_3$} -- (1.west); 
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容