如何使用 TikZ 获取图中顶点后的边?

如何使用 TikZ 获取图中顶点后的边?

以下代码给了我一个图形,如何一个接一个地显示边,而不是一次显示整个图形。

\begin{figure}
\begin{tikzpicture}
  [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
  %\node (n6) at (1,10) {6};
  \node (n4) at (3,4)  {4};
  \node (n5) at (3,2)  {5};
  \node (n1) at (1.5,2)  {1};
  \node (n2) at (3,6)  {2};
  \node (n3) at (4.5,2)  {3};

  \foreach \from/\to in {n2/n4,n4/n3,n4/n5,n4/n1}
    \draw (\from) -- (\to);
\draw (n2) to [out=-20,in=35] (n3);
\draw (n2) to [out=200,in=135] (n1);
\draw (n2) to [out=-20,in=35] (n5);
\end{tikzpicture}
\caption{Closure of a Tree}
\end{figure}

答案1

你可以利用 TikZ 命令具有重叠感知功能这一事实(我使用\visible弯曲箭头来防止图形“跳来跳去”):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}

\begin{document}

\begin{frame}
\begin{figure}
\centering
\begin{tikzpicture}
  [scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
  %\node (n6) at (1,10) {6};
  \node (n4) at (3,4)  {4};
  \node (n5) at (3,2)  {5};
  \node (n1) at (1.5,2)  {1};
  \node (n2) at (3,6)  {2};
  \node (n3) at (4.5,2)  {3};

  \foreach \from/\to [count=\xi from 2] in {n2/n4,n4/n3,n4/n5,n4/n1}
    \draw<\xi-> (\from) -- (\to);
\visible<6->{\draw (n2) to [out=-20,in=35] (n3);}
\visible<7->{\draw (n2) to [out=200,in=135] (n1);}
\draw<8-> (n2) to [out=-20,in=35] (n5);
\end{tikzpicture}
\caption{Closure of a Tree}
\end{figure}
\end{frame}

\end{document}

在此处输入图片描述

相关内容