我在 tikz/beamer 环境中制作了一个简单的动画图形。问题是,当我点击其中一张幻灯片时,全部动画开始移动。我要找的是幻灯片 2 上的 S 开始稍微摇晃。在幻灯片 3 上,我希望 PRD 和连接 R 到 PRD 的扩展箭头同时出现。幻灯片 4 上的 R 和 PSD 也是如此。等等...
\documentclass[compress]{beamer}
\usepackage{pgfpages}
\usepackage[ngerman]{babel}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,through,backgrounds,positioning,fit,petri}
\usetikzlibrary{shapes,shadows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{animateinline}[]{10}
\multiframe{10}{r = 1 + 1, rP = 0.1 + .1}{
\begin{tikzpicture}
[demand/.style={rounded rectangle, minimum size=8mm, minimum width=20mm, text width=1.2cm, text height=-.45cm, fill=blue!20!white, font=\tiny, text centered},
rect/.style={rectangle, font=\tiny},
cris/.style={ellipse, minimum size=8mm, minimum width=15mm, text width=1.3cm, text height=0cm, fill=red!10!white, font=\tiny, text centered},
post/.style={->,>=stealth', very thin, draw=black!50}]
\onslide<1->\node (b) at (0,0) [rect, fill=blue!30!white] {R};
\onslide<2->\node (r) at (2,0) [cris, decorate, decoration={random steps,segment length=3pt,amplitude=\r}] {S};
\onslide<3->\node (d) at (3,-2) [demand] {PRD};
\onslide<3->\path (b.east) -- (d.west) node[pos=\rP] (p){};
\draw[post] (b.east) -- (p.west);
\onslide<4->\node (c) at (3,2) [demand] {PSD};
\onslide<4->\path (b.east) -- (c.west) node[pos=\rP] (q){};
\draw[post] (b.east) -- (q.west);
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
希望有人可以帮忙!
更新:
感谢安德鲁的快速回复!问题是,当你点击其中一张幻灯片时,全部动画开始移动。我要找的是幻灯片 2 上的 S 开始稍微摇晃。在幻灯片 3 上,我希望 PRD 和连接 R 到 PRD 的扩展箭头同时出现。幻灯片 4 上的 R 和 PSD 也是如此。
\documentclass[compress]{beamer}
\usepackage{pgfpages}
\usepackage[ngerman]{babel}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,through,backgrounds,positioning,fit,petri}
\usetikzlibrary{shapes,shadows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{animateinline}[]{10}
\multiframe{10}{r = 1 + 1, rP = 0.1 + .1}{
\begin{tikzpicture}
[demand/.style={rounded rectangle, minimum size=8mm, minimum width=20mm, text width=1.2cm, text height=-.45cm, fill=blue!20!white, font=\tiny, text centered},
rect/.style={rectangle, font=\tiny},
cris/.style={ellipse, minimum size=8mm, minimum width=15mm, text width=1.3cm, text height=0cm, fill=red!10!white, font=\tiny, text centered},
post/.style={->,>=stealth', very thin, draw=black!50}]
\onslide<1->\node (b) at (0,0) [rect, fill=blue!30!white] {R};
\onslide<2->\node (r) at (2,0) [cris, decorate, decoration={random steps,segment length=3pt,amplitude=\r}] {S};
\onslide<3->\node (d) at (3,-2) [demand] {PRD};
\onslide<3->\path (b.east) -- (d.west) node[pos=\rP] (p){};
\draw[post] (b.east) -- (p.west);
\onslide<4->\node (c) at (3,2) [demand] {PSD};
\onslide<4->\path (b.east) -- (c.west) node[pos=\rP] (q){};
\draw[post] (b.east) -- (q.west);
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
答案1
我想我明白了 Helga 的想法。她可能想要一个动画,该动画分为几个阶段,中间有暂停,用户必须执行某些操作才能继续。为此,动画包提供了命令\newframe*
。它引入了所需的中断。单击动画后,它将继续播放。请参阅下面列出的代码。现在,整个动画位于一个 Beamer 幻灯片上(\onslide
已删除)。代码仍然可以通过使用时间线(参见动画文档)在 PDF 大小方面进行优化,它允许嵌入对象一次并在其他动画帧中引用它们(使用 PDF XObjects)。
\documentclass[compress]{beamer}
\usepackage{pgfpages}
\usepackage[ngerman]{babel}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,through,backgrounds,positioning,fit,petri}
\usetikzlibrary{shapes,shadows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{animateinline}[
begin={%
\begin{tikzpicture}%
[demand/.style={rounded rectangle, minimum size=8mm, minimum width=20mm, text width=1.2cm, text height=-.45cm, fill=blue!20!white, font=\tiny, text centered},%
rect/.style={rectangle, font=\tiny},%
cris/.style={ellipse, minimum size=8mm, minimum width=15mm, text width=1.3cm, text height=0cm, fill=red!10!white, font=\tiny, text centered},%
post/.style={->,>=stealth', very thin, draw=black!50}]%
\useasboundingbox (-0.25,-2.5) rectangle (4,2.5); %all frames having the same size
},
end={\end{tikzpicture}}
]{10}
\node (b) at (0,0) [rect, fill=blue!30!white] {R}; %[R] alone
\newframe*
\multiframe{10}{r = 1 + 1}{ %shaking `S'
\node (b) at (0,0) [rect, fill=blue!30!white] {R};
\node (r) at (2,0) [cris, decorate, decoration={random steps,segment length=3pt,amplitude=\r}] {S};
}
\newframe*
\multiframe{10}{rP = 0.1 + .1, r = 1 + 1}{ %-->(PRD)
\node (b) at (0,0) [rect, fill=blue!30!white] {R};
\node (r) at (2,0) [cris, decorate, decoration={random steps,segment length=3pt,amplitude=\r}] {S};
\node (d) at (3,-2) [demand] {PRD};
\path (b.east) -- (d.west) node[pos=\rP] (p){};
\draw[post] (b.east) -- (p.west);
}
\newframe*
\multiframe{10}{rP = 0.1 + .1, r = 1 + 1}{ %-->(PSD)
\node (b) at (0,0) [rect, fill=blue!30!white] {R};
\node (r) at (2,0) [cris, decorate, decoration={random steps,segment length=3pt,amplitude=\r}] {S};
\node (d) at (3,-2) [demand] {PRD};
\path (b.east) -- (d.west) node[pos=1] (p){};
\draw[post] (b.east) -- (p.west);
\node (c) at (3,2) [demand] {PSD};
\path (b.east) -- (c.west) node[pos=\rP] (q){};
\draw[post] (b.east) -- (q.west);
}
\end{animateinline}
\end{frame}
\end{document}
答案2
我无法测试这个答案因为我没有与该animate
软件包兼容的 PDF 查看器。但是,我思考这会达到你想要的效果。为了测试它,我在没有 animate 包的情况下运行它,并手动循环遍历帧,将变量设置为我想要的任何值。关键是使用部分修饰语指定箭头的目标。为此,您需要使用calc
TikZ 库。有关语法的更多信息,请参阅 PGF 手册(版本 2.10,其他版本可能有不同的编号)中的第 13.5.3 节。
这就是答案没有animate 包。<1-10>
和\pgfmath
内容是模拟动画的循环。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\r{3}
\def\s{0}
\begin{frame}<1-10>
\pgfmathsetmacro{\r}{2 + \r}
\pgfmathsetmacro{\s}{.1 + \s}
\global\let\r=\r
\global\let\s=\s
\begin{tikzpicture}[every node/.style={fill=green!50!white}]
\onslide<1->\node (b) at (-1,0) [ rectangle] {R};
\onslide<2->\node (r) at (1.4,0) [circle, minimum size=\r pt,xshift=-5mm] {S};
\onslide<3->\node (d) at (2.5,-2) [circle,xshift=-5mm] {PRD};
\onslide<3->\draw [->] (b.east) -- ($(b.east)!\s!(d.west)$);
\onslide<4->\node (c) at (2.5,2) [circle, xshift=-5mm] {PSD};
\onslide<4->\draw [->] (b.east) -- ($(b.east)!\s!(c.west)$);
\end{tikzpicture}
\end{frame}
\end{document}
这是使用 animate 包的答案。请注意,我假设了很多无法在这里测试的内容。
\documentclass{beamer}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}
\begin{animateinline}[palindrome]{10}
\multiframe{10}{r=3 + 2,s=0+.1}{
\begin{tikzpicture}[every node/.style={fill=green!50!white}]
\onslide<1->\node (b) at (-1,0) [ rectangle] {R};
\onslide<2->\node (r) at (1.4,0) [circle, minimum size=\r pt,xshift=-5mm] {S};
\onslide<3->\node (d) at (2.5,-2) [circle,xshift=-5mm] {PRD};
\onslide<3->\draw [->] (b.east) -- ($(b.east)!\s!(d.west)$);
\onslide<4->\node (c) at (2.5,2) [circle, xshift=-5mm] {PSD};
\onslide<4->\draw [->] (b.east) -- ($(b.east)!\s!(c.west)$);
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
(为了回答这个问题,我严重压缩了你的代码。事实上,我最初以为我不会能够回答这个问题,只是想帮助你将代码压缩成问题显而易见的东西。但在压缩代码的过程中,我有了一个想法,所以把它变成了一个答案。)