如何使用 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 命令具有 overlat 感知這一事實(我使用\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}

在此輸入影像描述

相關內容