![Beamer 中的 tikzpicture:如何在 foreach 语句中发现节点](https://linux22.com/image/250055/Beamer%20%E4%B8%AD%E7%9A%84%20tikzpicture%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%20foreach%20%E8%AF%AD%E5%8F%A5%E4%B8%AD%E5%8F%91%E7%8E%B0%E8%8A%82%E7%82%B9.png)
如何发现以下 tikzpicture 中的节点?我想显示所有红色节点,然后显示所有绿色节点,然后显示所有蓝色节点。
\tikzstyle{level 1}=[sibling angle=120]
\tikzstyle{level 2}=[sibling angle=60]
\tikzstyle{level 3}=[sibling angle=30]
\tikzstyle{every node}=[fill,inner sep=0pt,minimum size=4pt]
\tikzstyle{edge from parent}=[segment length=1mm,
segment angle=10,draw]
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round,scale=0.5]
\node {} child [color=\A] foreach \A in {red,red,red}
{ node {} child [color=\A!50!\B] foreach \B in {green,green,green}
{ node {} child [color=\A!50!\B!50!\C] foreach \C in {blue,blue,blue}
{ node {} }
}
};
\end{tikzpicture}
答案1
在这个解决方案中,我应用了 Daniel 的方法思维导图 tikzpicture 在 beamer 中 (逐步显示):它有几个优点,而且使用起来非常简单。
在下面的代码中,根据提供的 MWE,我在序言中改变了样式定义:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees,decorations}
\usetheme{EastLansing}
% style definitions
\tikzset{level 1/.style={sibling angle=120}}
\tikzset{level 2/.style={sibling angle=60}}
\tikzset{level 3/.style={sibling angle=30}}
\tikzset{every node/.style={fill,inner sep=0pt,minimum size=4pt}}
\tikzset{edge from parent/.style={segment length=1mm,
segment angle=10,draw}}
% Daniel's code:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer/55827#55827
\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}{Title}
\begin{center}
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round,scale=0.5]
\node {} child [color=\A,visible on=<1->] foreach \A in {red,red,red}
{ node {} child [color=\A!50!\B,visible on=<2->] foreach \B in {green,green,green}
{ node {} child [color=\A!50!\B!50!\C,visible on=<3->] foreach \C in {blue,blue,blue}
{ node {} }
}
};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
您只需要在序言中插入丹尼尔的代码后,定义您想要显示节点的时间点;方法是添加child
选项visible on=<...>
。
最后你得到的是这三个框架: