使用带有 \onslide\visible\only inside beamer 的 Tikz 定位

Using Tikz positioning with \onslide\visible\only inside beamer

我有以下图片:

并且我希望它的元素在我的 beamer 演示文稿中以特定顺序出现。目前,我正在尝试让 a_1、a_2 出现在第二张幻灯片中。我正在使用此代码:

\documentclass{beamer}
\usepackage{textcomp}
\usepackage{tikz}
\usetheme{Madrid}
\begin{document}
\begin{frame}{}
 \usetikzlibrary{shapes,arrows, positioning, calc}  
 
\tikzset{%
  block/.style    = {rounded corners, draw, thick, circle, minimum height = 3em,
    minimum width = 3em, fill = yellow!50},
  point/.style    = {coordinate}, % Input
}
\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
%\node[block] (A1) at (0,0) {$A_1$};
%\node[block, right  = 1cm of A1] (A2) {$A_2$};
\node[below  = of A1] (a1) {{\visible<2->{$a_1$}}};
\node[below  = of A2] (a2) {{\visible<2->{$a_2$}}};
\node[below  = of A1] (a1) {$a_1$};
\node[below  = of A2] (a2) {$a_2$};
\draw[->] (A1.south) ++(0,-0.3) -- ++(0, -1.3);
\draw[->] (A2.south) ++(0,-0.3) -- ++(0, -1.3);
\end{tikzpicture}
\end{frame}
\end{document}

但我得到的只是这个:

我收到类似这样的错误:“未知箭头类型 'triangle 45'”以及“(A1 的)未知运算符 'o' 或 'of '”。 这是我第一次使用 Tikz,我对像 \onslide、\only 或 \visible 这样的 beamer 工具不太实用。我想我可以创建不同的图像,每个帧一个,然后用 \includegraphics 和 \pause 添加它们,但如果我设法在不创建不同图片的情况下获得相同的结果,那会更实用。任何帮助将不胜感激。

  • 在序言中加载您的 tikz 库,而不是在框架内

  • 你可以使用overlay-beamer-styles库来控制节点的外观

\documentclass{beamer}
\usepackage{textcomp}
\usepackage{tikz}
\usetheme{Madrid}

 \usetikzlibrary{shapes,arrows, positioning, calc}  
 \usetikzlibrary{overlay-beamer-styles}
 
\tikzset{%
  block/.style    = {rounded corners, draw, thick, circle, minimum height = 3em,
    minimum width = 3em, fill = yellow!50},
  point/.style    = {coordinate}, % Input
}


\begin{document}
\begin{frame}{}
\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
\node[block] (A1) at (0,0) {$A_1$};
\node[block, right  = 1cm of A1] (A2) {$A_2$};
\node[below  = of A1, visible on=<2->] (a1) {$a_1$};
\node[below  = of A2, visible on=<2->] (a2) {$a_2$};
\draw[->] (A1.south) ++(0,-0.3) -- ++(0, -1.3);
\draw[->] (A2.south) ++(0,-0.3) -- ++(0, -1.3);
\end{tikzpicture}
\end{frame}
\end{document}