使用LaTeX animate和Tikz有两个嵌套循环

问题描述 投票:1回答:1

我正在尝试使用带有两个嵌套循环的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}
animation latex beamer
1个回答
0
投票

问题是未受保护的行结尾,由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}

enter image description here

(由于转换为.gif,控制键在上图中不可见,它们在原始pdf中工作正常)

© www.soinside.com 2019 - 2024. All rights reserved.