Controlsaligned 和控件在 tikz 中不起作用

Controlsaligned 和控件在 tikz 中不起作用

我正在尝试使用controlsaligned并仅显示play,stop,step控制器中的按钮。这是我正在使用的代码

 \documentclass[12pt]{article}
    \usepackage{tikz}
    \usepackage[utf8]{inputenc}
    \usepackage{xcolor}
    \definecolor{lava}{rgb}{0.81, 0.06, 0.13}
    \definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
    \usepackage{gensymb}
    \usetikzlibrary{shapes}
    \usepgflibrary{shapes.symbols}
    \usetikzlibrary{mindmap,trees,arrows,shapes.symbols,shapes.misc}
    \usepackage[ampersand]{easylist}
    \usepackage{lmodern}  
    \pagestyle{empty}
    \usetikzlibrary{decorations.markings}
    \usepackage{ifthen}
\usepackage{animate}  
   \newcounter{angle}
\setcounter{angle}{0}
\begin{document}
\begin{center}
  \begin{animateinline}[loop, poster = first,controls={[play,stop,speed]},controlsaligned=right+-4em]
\whiledo{\theangle<359}{
\vspace{-1em}
    \begin{tikzpicture}[scale=0.9]    
    % Axis
    \draw[thick,->,black] (-3,0)--(3,0) node[below] {$\Re$}; % x axis
    \draw[thick,->,black] (0,-3)--(0,3) node[left] {$\Im$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \node[black,below] at (2.6,0) {$V_m$};
    \node[black,above] at (0.1,-2.5) {$V_m$};
    %
    \draw[ultra thick,lava] (0,0) -- (0,0 |- \theangle:2.5cm); % UpOn x axis
    \draw[ultra thick,myblue] (0,0) -- (\theangle:2.5cm |- 0,0); % UpOn y axis
    %
    \draw[densely dotted,lava] (\theangle:2.5cm) -- (\theangle:2.5cm |- 0,0); % vertical line
    \draw[densely dotted,myblue] (\theangle:2.5cm) -- (0,0 |- \theangle:2.5cm); % horizontal line
    \draw[ultra thick,black,->,rotate=\theangle] (0,0) -- (2.5,0); 
    \node[red,myblue,right] at (0,-3.1) 
            {\footnotesize$\cos(\theangle^{\degree}) = \pgfmathcos{\theangle}\pgfmathresult$};
    \node[lava,lava,right] at (0,-3.5) 
            {\footnotesize$\sin(\theangle^{\degree}) = \pgfmathsin{\theangle}\pgfmathresult$};
    \end{tikzpicture}
    %
    \stepcounter{angle}
    \ifthenelse{\theangle<359}{
            \newframe
    }{
    
            \end{animateinline}
    }
}
\end{center}
\end{document}

错误是

​!缺失数字,视为零。

答案1

代码中存在一些语法错误:[]周围的play,stop,speed是错误的,并且环境中缺少帧速率参数animateinline

此外,代码使用\whiledo参数化框架的循环,这是不推荐的做法。请改用\multiframe

为了防止动画在运行过程中摆动,将一个不可见的节点放入其中,tikzpicture以稍微推动其右边界框边缘。这可确保所有帧都具有相同的大小。

请注意,使用负尺寸controlsaligned会导致控件突出到动画小部件之外。不确定这是否是您的意图。(我在下面的代码中删除了它。)

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}  
\usepackage{lmodern}  
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{gensymb}
\pagestyle{empty}
\usepackage{animate}   
    
\begin{document}
\begin{center}
\begin{animateinline}[loop, poster = first,controls={play,stop,speed},controlsaligned=right]{30}
  \multiframe{360}{iAngle=0+1}{
    \begin{tikzpicture}[scale=0.9]
    \node at (3.9,0) {}; % push right bounding box border somewhat 
    % Axis
    \draw[thick,->] (-3,0) -- (3,0) node[right] {$\Re$}; % x axis
    \draw[thick,->] (0,-3)--(0,3) node[left] {$\Im$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \node[black,below] at (2.6,0) {$V_m$};
    \node[black,above] at (0.1,-2.5) {$V_m$};
    %
    \draw[ultra thick,lava] (0,0) -- (0,0 |- \iAngle:2.5cm); % UpOn x axis
    \draw[ultra thick,myblue] (0,0) -- (\iAngle:2.5cm |- 0,0); % UpOn y axis
    %
    \draw[densely dotted,lava] (\iAngle:2.5cm) -- (\iAngle:2.5cm |- 0,0); % vertical line
    \draw[densely dotted,myblue] (\iAngle:2.5cm) -- (0,0 |- \iAngle:2.5cm); % horizontal line
    \draw[ultra thick,black,->,rotate=\iAngle] (0,0) -- (2.5,0);
    \node[red,myblue,right] at (0,-3.1)
            {\footnotesize$\cos(\iAngle^{\degree}) = \pgfmathcos{\iAngle}\pgfmathresult$};
    \node[lava,lava,right] at (0,-3.5)
            {\footnotesize$\sin(\iAngle^{\degree}) = \pgfmathsin{\iAngle}\pgfmathresult$};
    \end{tikzpicture}
  }
\end{animateinline}
\end{center}
\end{document}

相关内容