我正在尝试制作一个涉及 L 系统的投影仪演示,并且希望一次展示 L 系统的步骤。目前我有代码:
\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\begin{frame}
\frametitle{title}
\begin{center}
\def\intervalwidth{9cm}%
\pgfdeclarelindenmayersystem{CantorMiddleThirds}{
\symbol{X}{\pgflsystemdrawforward}
\symbol{Y}{\pgflsystemmoveforward}
\rule{X -> XYX}
\rule{Y -> YYY}
}
\foreach \level in {0,...,5}{
\begin{tikzpicture}
\draw [line width = 5pt] (0,0) l-system
[l-system={CantorMiddleThirds, axiom=X,step=\intervalwidth/(3^\level), order=\level, angle=0},fill=black];
\end{tikzpicture}
\pause
}
\end{center}
\end{frame}
\end{document}
当我编译时,我得到了一个完全符合我预期的 PDF,但是编译器抛出了一个错误:
Package pgf Error: Lindenmayer system `CantorMiddleThirds' is already defined. \end{frame}
每次循环迭代都会出现一次。我想知道哪个交互导致了此错误,以及如何避免它。
答案1
\pgfdeclarelindenmayersystem{CantorMiddleThirds}
如果移出框架,则不会出现编译错误。类beamer
会多次处理框架内容。
\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\pgfdeclarelindenmayersystem{CantorMiddleThirds}{
\symbol{X}{\pgflsystemdrawforward}
\symbol{Y}{\pgflsystemmoveforward}
\rule{X -> XYX}
\rule{Y -> YYY}
}
\begin{document}
\begin{frame}
\frametitle{title}
\begin{center}
\def\intervalwidth{9cm}%
\foreach \level in {0,...,5}{
\begin{tikzpicture}
\draw [line width = 5pt] (0,0) l-system
[l-system={CantorMiddleThirds, axiom=X,step=\intervalwidth/(3^\level),
order=\level, angle=0},fill=black];
\end{tikzpicture}
\pause
}
\end{center}
\end{frame}
\end{document}