首页 > 解决方案 > 使用带有 \onslide\visible\only 的 Tikz 定位在投影仪内

问题描述

我有以下图像: 在此处输入图像描述

我希望它的元素在我的投影仪演示中以一定的顺序出现。目前,我正在尝试让 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}

但我得到的是:

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

标签: latexbeamertikz

解决方案


  • 在序言中加载您的 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}

在此处输入图像描述


推荐阅读