\pause
使用beamer
和\foreach
的命令tikz
可以创建作为视频动画图层的幻灯片。
例如:
\documentclass{beamer}
\usepackage{pgf,tikz}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
\foreach \x in {1,2,...,4}{
\only<\x>{
\clip (0,0) rectangle (8,4.5);
\draw[line width=6pt] (0,0) rectangle (8,4.5);
\fill (2*\x,\x) circle (.2); % animated object
}
}
\end{tikzpicture}
\end{frame}
\end{document}
我想创建一个新的环境,如下所示:
\documentclass{beamer}
\usepackage{pgf,tikz}
\newenvironment{animation}[1]{
\begin{frame}
\begin{tikzpicture}
\foreach \x in {1,2,...,#1}{
\only<\x>{
}{
}
}
\end{tikzpicture}
\end{frame}
}
\begin{document}
\begin{animation}{4}
\clip (0,0) rectangle (8,4.5);
\draw[line width=6pt] (0,0) rectangle (8,4.5);
\fill (2*\x,\x) circle (.2);
\end{animation}
\end{document}
但这样做不行。有人知道怎么做吗?是否可以做到?
答案1
尝试\NewDocumentEnvironment
:
\documentclass{beamer}
\usepackage{pgf,tikz}
\NewDocumentEnvironment{animation}{m +b}{
\begin{frame}
\begin{tikzpicture}
\foreach \x in {1,2,...,#1}{
\only<\x>{#2}
}
\end{tikzpicture}
\end{frame}
}{}
\begin{document}
\begin{animation}{4}
\clip (0,0) rectangle (8,4.5);
\draw[line width=6pt] (0,0) rectangle (8,4.5);
\fill (2*\x,\x) circle (.2);
\end{animation}
\end{document}