Subtleties of step-by-step tikz-tree revealing
I am using the very elegant method from user Daniel described here to try and reveal my tikz-tree gradually. The brief idea is that the tree is always fully drawn to avoid "jumpy" nodes and make their coordinates available even if they are "invisible", but that the opacity is set to 0 on those nodes that are not supposed to be seen yet.
This is how my complete tree should look like after the reveal (I apologize in advance for the miserable quality of my phone's camera):
Here is my code:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{inputenc}[utf8]
\usetikzlibrary{trees}
% Daniel's proposal for "uncovering" parts of a tikz-tree %
\tikzset{
invisible/.style={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}[
nor/.style={circle,thick,solid,draw=black,fill=none,inner sep=0.5mm, minimum size=5mm},
acc/.style={circle,thick,solid,draw=green!50!black,fill=green!20,inner sep=0.5mm, minimum size=5mm},
rej/.style={circle,thick,solid,draw=red!50,fill=red!20,inner sep=0.5mm, minimum size=5mm},
level 1/.style={every child/.style={edge from parent/.style={dashed,draw,nearly opaque}} },
level 2/.style={sibling distance=19mm,every child/.style={edge from parent/.style={solid,draw}}},
level 3/.style={sibling distance=8mm,every child/.style={edge from parent/.style={dashed,draw,nearly opaque}} },
semithick]
\node[draw=none] (root) {}
child[level distance=12mm,visible on=<1->] { node[nor] {$x$}
child[visible on=<2->] {node[acc] {$e_1(x)$} }
child[visible on=<2->] {node[nor] {$e_2(x)$}
child[visible on=<6->] child[visible on=<6->] }
child[visible on=<2->] {node[rej] {$e_3(x)$} }
child[visible on=<2->] {node[nor] {$e_4(x)$}
child[visible on=<6->] child[visible on=<6->] child[visible on=<6->] }
};
\end{tikzpicture}
\end{frame}
\end{document}
The 4 sibling nodes on level 2 are correctly hidden, including their solid edges to/from the (x) node. But the dashed edges at the bottom of the tree are shown since the very first slide - even though the leaf nodes are set to be visible from slide 6 onwards.
Why is this happening? This way of doing things was accepted as an answer and received a lot of praise in the original question, so it works. It's just partially working for me.
How could I fix this?
I am using the very elegant method from user Daniel described here to try and reveal my tikz-tree gradually. The brief idea is that the tree is always fully drawn to avoid "jumpy" nodes and make their coordinates available even if they are "invisible", but that the opacity is set to 0 on those nodes that are not supposed to be seen yet.
This is how my complete tree should look like after the reveal (I apologize in advance for the miserable quality of my phone's camera):
Here is my code:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{inputenc}[utf8]
\usetikzlibrary{trees}
% Daniel's proposal for "uncovering" parts of a tikz-tree %
\tikzset{
invisible/.style={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}[
nor/.style={circle,thick,solid,draw=black,fill=none,inner sep=0.5mm, minimum size=5mm},
acc/.style={circle,thick,solid,draw=green!50!black,fill=green!20,inner sep=0.5mm, minimum size=5mm},
rej/.style={circle,thick,solid,draw=red!50,fill=red!20,inner sep=0.5mm, minimum size=5mm},
level 1/.style={every child/.style={edge from parent/.style={dashed,draw,nearly opaque}} },
level 2/.style={sibling distance=19mm,every child/.style={edge from parent/.style={solid,draw}}},
level 3/.style={sibling distance=8mm,every child/.style={edge from parent/.style={dashed,draw,nearly opaque}} },
semithick]
\node[draw=none] (root) {}
child[level distance=12mm,visible on=<1->] { node[nor] {$x$}
child[visible on=<2->] {node[acc] {$e_1(x)$} }
child[visible on=<2->] {node[nor] {$e_2(x)$}
child[visible on=<6->] child[visible on=<6->] }
child[visible on=<2->] {node[rej] {$e_3(x)$} }
child[visible on=<2->] {node[nor] {$e_4(x)$}
child[visible on=<6->] child[visible on=<6->] child[visible on=<6->] }
};
\end{tikzpicture}
\end{frame}
\end{document}
The 4 sibling nodes on level 2 are correctly hidden, including their solid edges to/from the (x) node. But the dashed edges at the bottom of the tree are shown since the very first slide - even though the leaf nodes are set to be visible from slide 6 onwards.
Why is this happening? This way of doing things was accepted as an answer and received a lot of praise in the original question, so it works. It's just partially working for me.
How could I fix this?
No comments:
Post a Comment