如何在 Beamer 中的 tikz 图片中分别显示与子节点相关的边缘?

如何在 Beamer 中的 tikz 图片中分别显示与子节点相关的边缘?

我在 Beamer 演示文稿中的 tikz 图片中画了一棵简单的树。顶部有一个根节点(“名称”),底部有一系列子节点(“E1”、“E2”等),还有从根到每个子节点的边。

我想在后续幻灯片中展示根节点,然后这些孩子,然后边缘。

我已经到达根节点,然后是带有节点的子节点:

梅威瑟:

\documentclass[presentation]{beamer}
\usepackage{tikz}                         
\usetikzlibrary{positioning}
\tikzset{hide on/.code={\only<#1>{\color{fg!0}}}}
\usetheme{default}

\begin{document}
\begin{frame}{Foo}

Foo.

% (this is how my actual doc is structured)
\pause{}

The theory must posit:\pause{}\onslide<3->{ a \alert{name},
\onslide<4->{some \alert{objects}, \onslide<5->{and
some \alert{relation} between them on each precisification.}}}

\begin{tikzpicture}[
  on grid,
  every child/.={edge from parent},
  font=\footnotesize,
  level distance=2cm,
  sibling distance=1cm]
  % Stuff here.
  \node[hide on=-2] (name) {Name}
  child[hide on=-3] {node {E1}}
  child[hide on=-3] {node {E2}}
  child[hide on=-3] {node {E3}}
  child[hide on=-3] {node {E4}}
  child[hide on=-3] {node {E5}}
  child[hide on=-3] {node {etc.}};
\end{tikzpicture}
\end{frame}
\end{document}

答案1

我认为,如果使用 child 操作,就不可能将子节点和它们到根节点的路径分开。你必须自己制作树。这可能是一个半自动树,你可以轻松地决定显示什么以及何时显示。

\documentclass[presentation]{beamer}

\usepackage{tikz}   

\usetheme{default}

\begin{document}

\begin{frame}{Foo}

Foo.

% (this is how my actual doc is structured)
\pause{}

The theory must posit:\pause{}\onslide<3->{ a \alert{name},
\onslide<4->{some \alert{objects}, \onslide<5->{and
some \alert{relation} between them on each precisification.}}}

\begin{tikzpicture}

\node(name) at (2.5,1.5) {Name}; % in order to obtain the x to put the root node at center you can do (last edge x +1)/2, in this case (4+1)/2=2.5

\onslide<4->{
\foreach \x/\y in {1/E1, 2/E2, 3/E3, 4/E4} \node(\y) at (\x,0) {\y}; %element list is positon/children, this shows childrens
}

\onslide<5->{
\foreach \y in {E1, E2} \draw (\y)--(name); %list of the children, this shows paths root-children you want
}

\onslide<6->{
\foreach \y in {E3, E4} \draw (\y)--(name);%if you want to show all edges togheter do one list with all of them
}
\end{tikzpicture}

\end{frame}

\end{document} 

相关内容