使用带有两个嵌套循环的 LaTeX 动画和 Tikz
Using LaTeX animate & Tikz with two nested loops
我正在尝试使用带有两个嵌套循环的 animate 包在 LaTeX 中创建动画,我在其中使用 Tikz 绘制图形。然而,图片在第一次和最后一次内部迭代中会保持轻微的重新缩放。在下面的最小示例中,我想绘制两个移动箭头:一个在顶部代表外层,一个在底部代表内层。
值得注意的是,如果内层只有一次迭代,即如果变量 \jlimit 为 1,则此问题消失。这似乎表明内层出了问题。
有没有人遇到过这个问题或者你能想到任何解决方案?
提前致谢:)
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{animate}
\newcounter{i} % Outer counter
\setcounter{i}{0}
\newcounter{j} % Inner counter
\def\ilimit{3} % Outer iteration limit
\def\jlimit{5} % Inner iteration limit, rescaling doesn't happen if this is 1
\begin{document}
\begin{frame}[fragile]{Nested animated loops}
\begin{center}
\begin{animateinline}[loop, poster = first, controls]{2}
\whiledo{\thei<\ilimit} { % Starting outer loop
\setcounter{j}{0} % Resetting inner counter
\whiledo{\thej<\jlimit} { % Starting inner loop
\begin{tikzpicture}
\draw [color=black] (-0.5,-1.5) rectangle (4.5, 0.5); % Draw a bounding rectangle
\node[shift={(\thei,0)}] at (0,0) {\Large $\downarrow$};% Draw the first level
\node[shift={(\thej,0)}] at (0,-1) {\Large $\uparrow$}; % Draw the second level
\end{tikzpicture}
\stepcounter{j} % Increase the inner counter
\ifthenelse{\thej<\jlimit} {
\newframe % Draw a new inner frame
}{}
}
\stepcounter{i} % Increase the outer counter
\ifthenelse{\thei<\ilimit} {
\newframe % Draw a new outer frame
}{
\end{animateinline}\relax % BREAK % End the animation
}
}
\end{center}
\end{frame}
\end{document}
问题是未受保护的行尾,它们被 tex 解释为空格。在行尾添加 %
符号以避免此问题:
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{animate}
\newcounter{i} % Outer counter
\setcounter{i}{0}
\newcounter{j} % Inner counter
\def\ilimit{3} % Outer iteration limit
\def\jlimit{5} % Inner iteration limit, rescaling doesn't happen if this is 1
\begin{document}
\begin{frame}[fragile]{Nested animated loops}
\begin{center}%
\begin{animateinline}[loop, poster = first, controls]{2}
\whiledo{\thei<\ilimit} {% % Starting outer loop
\setcounter{j}{0}% % Resetting inner counter
\whiledo{\thej<\jlimit} {% % Starting inner loop
\begin{tikzpicture}%
\draw [color=black] (-0.5,-1.5) rectangle (4.5, 0.5); % Draw a bounding rectangle
\node[shift={(\thei,0)}] at (0,0) {\Large $\downarrow$};% Draw the first level
\node[shift={(\thej,0)}] at (0,-1) {\Large $\uparrow$}; % Draw the second level
\end{tikzpicture}%
\stepcounter{j}% % Increase the inner counter
\ifthenelse{\thej<\jlimit} {%
\newframe% % Draw a new inner frame
}{}%
}%
\stepcounter{i}% % Increase the outer counter
\ifthenelse{\thei<\ilimit} {%
\newframe% % Draw a new outer frame
}{%
\end{animateinline}\relax% % BREAK % End the animation
}%
}%
\end{center}
\end{frame}
\end{document}
(由于转换为.gif,控制键在上图中不可见,它们在原始pdf中工作正常)
我正在尝试使用带有两个嵌套循环的 animate 包在 LaTeX 中创建动画,我在其中使用 Tikz 绘制图形。然而,图片在第一次和最后一次内部迭代中会保持轻微的重新缩放。在下面的最小示例中,我想绘制两个移动箭头:一个在顶部代表外层,一个在底部代表内层。
值得注意的是,如果内层只有一次迭代,即如果变量 \jlimit 为 1,则此问题消失。这似乎表明内层出了问题。
有没有人遇到过这个问题或者你能想到任何解决方案?
提前致谢:)
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{animate}
\newcounter{i} % Outer counter
\setcounter{i}{0}
\newcounter{j} % Inner counter
\def\ilimit{3} % Outer iteration limit
\def\jlimit{5} % Inner iteration limit, rescaling doesn't happen if this is 1
\begin{document}
\begin{frame}[fragile]{Nested animated loops}
\begin{center}
\begin{animateinline}[loop, poster = first, controls]{2}
\whiledo{\thei<\ilimit} { % Starting outer loop
\setcounter{j}{0} % Resetting inner counter
\whiledo{\thej<\jlimit} { % Starting inner loop
\begin{tikzpicture}
\draw [color=black] (-0.5,-1.5) rectangle (4.5, 0.5); % Draw a bounding rectangle
\node[shift={(\thei,0)}] at (0,0) {\Large $\downarrow$};% Draw the first level
\node[shift={(\thej,0)}] at (0,-1) {\Large $\uparrow$}; % Draw the second level
\end{tikzpicture}
\stepcounter{j} % Increase the inner counter
\ifthenelse{\thej<\jlimit} {
\newframe % Draw a new inner frame
}{}
}
\stepcounter{i} % Increase the outer counter
\ifthenelse{\thei<\ilimit} {
\newframe % Draw a new outer frame
}{
\end{animateinline}\relax % BREAK % End the animation
}
}
\end{center}
\end{frame}
\end{document}
问题是未受保护的行尾,它们被 tex 解释为空格。在行尾添加 %
符号以避免此问题:
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{animate}
\newcounter{i} % Outer counter
\setcounter{i}{0}
\newcounter{j} % Inner counter
\def\ilimit{3} % Outer iteration limit
\def\jlimit{5} % Inner iteration limit, rescaling doesn't happen if this is 1
\begin{document}
\begin{frame}[fragile]{Nested animated loops}
\begin{center}%
\begin{animateinline}[loop, poster = first, controls]{2}
\whiledo{\thei<\ilimit} {% % Starting outer loop
\setcounter{j}{0}% % Resetting inner counter
\whiledo{\thej<\jlimit} {% % Starting inner loop
\begin{tikzpicture}%
\draw [color=black] (-0.5,-1.5) rectangle (4.5, 0.5); % Draw a bounding rectangle
\node[shift={(\thei,0)}] at (0,0) {\Large $\downarrow$};% Draw the first level
\node[shift={(\thej,0)}] at (0,-1) {\Large $\uparrow$}; % Draw the second level
\end{tikzpicture}%
\stepcounter{j}% % Increase the inner counter
\ifthenelse{\thej<\jlimit} {%
\newframe% % Draw a new inner frame
}{}%
}%
\stepcounter{i}% % Increase the outer counter
\ifthenelse{\thei<\ilimit} {%
\newframe% % Draw a new outer frame
}{%
\end{animateinline}\relax% % BREAK % End the animation
}%
}%
\end{center}
\end{frame}
\end{document}
(由于转换为.gif,控制键在上图中不可见,它们在原始pdf中工作正常)