动画在树形图中不起作用

动画在树形图中不起作用

我正在尝试向以下树状图添加动画:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}


\tikzset{
every node/.style={draw,text width=2cm,drop shadow},
style1/.style= {rectangle, rounded corners=2pt, thin,align=center,fill=green!30},
style2/.style= {rectangle, rounded corners=6pt, thin,align=center,fill=green!60},
style3/.style= {rectangle,thin,align=left,fill=pink!60}
}

\begin{document}


\begin{tikzpicture}[
remember picture,
level 1/.style={sibling distance=40mm},
edge from parent/.style={->,draw},
>=latex]

% the initial tree ("root" and "text nodes")
\node[style1] {root}
child {node[style2] (c1) {text}}
child {node[style2] (c2) {text}}
child {node[style2] (c3) {text}};

% the nodes below each of the "text" nodes
\node [style3,below of = c1,xshift=15pt] (c11) {A};
\node [style3,below of = c11] (c12) {A};
\node [style3,below of = c12] (c13) {A};

\node [style3,below of = c2,xshift=15pt] (c21) {B};
\node [style3,below of = c21] (c22) {B};
\node [style3,below of = c22] (c23) {B};
\node [style3,below of = c23] (c24) {B};

\node [style3,below of = c3,xshift=15pt] (c31) {C};
\node [style3,below of = c31] (c32) {C};
\node [style3,below of = c32] (c33) {C};
\node [style3,below of = c33] (c34) {C};
\node [style3,below of = c34] (c35) {C};

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

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

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

\end{document}

并且我已经添加了可见内容,如您在上面看到的那样,但是没有得到动画效果,我得到了没有任何效果的稳定物品阴影,因此非常感谢您的帮助。

在此处输入图片描述

答案1

你提到了visible on所以我假设你使用 beamer 文档和overlay-beamer-styles。然后默认情况下阴影保持可见,你需要将其关闭。为此我添加了一个样式

svisible on/.style={alt=#1{}{opacity=0,every shadow/.style={opacity=0}}}

阴影也会消失。(我还更改了语法以使用positioning您正在加载的。)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,trees,overlay-beamer-styles}


\tikzset{
every node/.style={draw,text width=2cm,drop shadow},
style1/.style= {rectangle, rounded corners=2pt, thin,align=center,fill=green!30},
style2/.style= {rectangle, rounded corners=6pt, thin,align=center,fill=green!60},
style3/.style= {rectangle,thin,align=left,fill=pink!60},
svisible on/.style={alt=#1{}{opacity=0,every shadow/.style={opacity=0}}}
}

\begin{document}

\begin{frame}
\frametitle{}
\begin{tikzpicture}[remember picture,
level 1/.style={sibling distance=40mm},
edge from parent/.style={->,draw},
>=latex,node distance=1.2em]

% the initial tree ("root" and "text nodes")
\node[style1] {root}
child[svisible on=<2->] {node[style2] (c1) {text}}
child[svisible on=<3->] {node[style2] (c2) {text}}
child[svisible on=<4->] {node[style2] (c3) {text}};

% the nodes below each of the "text" nodes
\begin{scope}[svisible on=<2->]
\node [style3,below=of c1,xshift=15pt] (c11) {A};
\node [style3,below=of c11] (c12) {A};
\node [style3,below=of c12] (c13) {A};
\foreach \value in {1,2,3}
  \draw[->] (c1.195) |- (c1\value.west);
\end{scope}

\begin{scope}[svisible on=<3->]
\node [style3,below=of c2,xshift=15pt] (c21) {B};
\node [style3,below=of c21] (c22) {B};
\node [style3,below=of c22] (c23) {B};
\node [style3,below=of c23] (c24) {B};
\foreach \value in {1,...,4}
  \draw[->] (c2.195) |- (c2\value.west);
\end{scope}

\begin{scope}[svisible on=<4->]
\node [style3,below=of c3,xshift=15pt] (c31) {C};
\node [style3,below=of c31] (c32) {C};
\node [style3,below=of c32] (c33) {C};
\node [style3,below=of c33] (c34) {C};
\node [style3,below=of c34] (c35) {C};
\foreach \value in {1,...,5}
  \draw[->] (c3.195) |- (c3\value.west);
\end{scope}

\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容