Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Following this question of mine, I now need to make a presentation using Beamer.

If you look at the plot below, it has some values on the arrows namely p1, 1-p1, ... I want to put the graph structure first and then when pressing the arrow key get the values showing one by one.
Just writing \pause in front of the nodes doesn't work, that would have been too simple. I don't know how to make it happen, anyone help?

\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}

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use visible on style (see Mindmap tikzpicture in beamer (reveal step by step)). This one is used in code below but there are some other options not far away provided by Matthew Leingang, Claudio Fiandrino, Qrrbrbirlbel or Gonzalo Medina just to mention some of them.

\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}

enter image description here

share|improve this answer
    
Works well thanks. I had to fiddle around with visible on=<2-> and set the value to be 5 and above for it to work. Does this represent the nth click? And how can I know apart from trial and error method? –  TAllieri Jun 9 at 14:36
1  
@TAllieri: Yes the number represent the nth click. <2-> means it will be shown from second in advance, <2> only on second frame, <2-4> on second, third and foorth frame, ... If you previously plan how the labels are shown you know the frame number. In any case I've included some other answer which can help you. –  Ignasi Jun 9 at 14:43
    
Apparently now there's the aobs-tikz package for the purpose of combining TikZ and beamer overlay –  Kevin C Jun 9 at 17:47
    
@KevinC Yes the aobs-tikz package was the result of Claudio's answer linked in my answer. –  Ignasi Jun 9 at 18:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.