添加可以在输出中按顺序查看的 tikzpicture 层(Motzkin 图)

添加可以在输出中按顺序查看的 tikzpicture 层(Motzkin 图)

在 Beamer 演示文稿中,可以按顺序向页面上的 tikzfigure 添加元素,这样查看者就不必一次性处理所有复杂性。但是,您不能在书籍文档类中使用 Beamer 命令。是否可以使用 tikz 向图表添加图层,例如电子书中的交互式图形?查看者应该能够通过鼠标单击来浏览帧序列。

答案1

这是一个笨拙的例子,说明了我使用 animate 包和 tikz 可以实现什么——@AlexG 给了一个很好的建议!我用 pdflatex 编译了文件,并可以在运行 OS 10.5.8 的 Mac 上使用 Adob​​e Acrobat Pro 9.5.1 查看图表上的图层。这对于我想要的简单图表来说已经足够了,但如果我可以删除一些重复,我会进行修改。

\documentclass[a4paper]{article}
\usepackage{xcolor,tikz,animate,fancyvrb}
\begin{document}
\usetikzlibrary{arrows,matrix,positioning,fit,calc}

% A clunky attempt to make the process of layering tikz pictures
% without having to reproduce previous layers through using a timeline file in animate

\centering
% Sample_timeline is a textfile that adds the 
% frames defined below one at a time.
\begin{VerbatimOut}{Sample_timeline}
::0x0
::1x0
::2x0
::3x0
\end{VerbatimOut}

\begin{animateinline}[
  step,controls,timeline=Sample_timeline,
  begin={%
    \begin{tikzpicture}%
    \useasboundingbox (-0.5,-0.5) rectangle (10,9.5);%
  },
  end={\end{tikzpicture}}
]{1} %although not relavant (option `step') fps is required argument
  \coordinate (Origin)   at (0,0);
  \coordinate (XAxisMin) at (0,0);
  \coordinate (XAxisMax) at (10,0);
  \coordinate (YAxisMin) at (0,0);
  \coordinate (YAxisMax) at (0,9);
  \draw [thin, gray,-latex] (XAxisMin) -- (XAxisMax) node [right] {$n$}; % Draw x axis
  \draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax) node [left] {$j$};% Draw y axis

  \pgftransformcm{1}{0}{0}{1}{\pgfpoint{0cm}{0cm}}
  \coordinate (Btwo) at (8,8);

  \coordinate (Arrowvertex) at (2,6);
  \coordinate (Arrowa) at (3,7);
  \coordinate (Arrowb) at (3,6);
  \coordinate (Arrowc) at (3,5);

  \draw[style=help lines,dashed] (0,0) grid[step=1cm] (10,9);
  \foreach \x in {0,...,8}{% Two indices running over each
  \foreach \y in {0,...,\x}{% node on the grid we have drawn 
   \node[draw,circle,inner sep=2pt,fill] at (1*\x,1*\y) {};
     % Places a dot at those points
    }
  }

  \coordinate (Testlabel) at (8,6);

  \foreach \x in {0,...,8}{
    \foreach \y in {0,...,7}{
      \draw [gray] node [below] at (1*\x,0) {\x};
      \draw [gray] node [left] at (0,1*\y) {\y};
    } 
  }

  \draw (Testlabel) node [above right] {$ n \ge j $};

  \draw [thick,-latex,black] (Arrowvertex) -- (Arrowa) node [pos=0.7,left] {$a_{j+1}$} ;
  \draw [thick,-latex] (Arrowvertex) -- (Arrowb) node [pos=1.1, above left] {$b_{j}$};
  \draw [thick,-latex] (Arrowvertex) -- (Arrowc) node [pos=0.5,below] {$a_{j}$};

  \foreach \x in {3}{
    \foreach \y in {5,6,7}{
      \node[draw,circle,inner sep=2pt,fill] at (1*\x,1*\y) {};
    }
  }

  \foreach \x in {2}{
    \foreach \y in {6}{
      \node[draw,circle,inner sep=2pt,fill] at (1*\x,1*\y) {};
    }
  }
\newframe
  % these commands allow me to superimpose the paths on the coordinates
  % defined by the grid in the previous frame (frame 0) without having
  % to draw it again =  more efficient diagram making.
  \coordinate (Origin)   at (0,0);
  \coordinate (XAxisMin) at (0,0);
  \coordinate (XAxisMax) at (10,0);
  \coordinate (YAxisMin) at (0,0);
  \coordinate (YAxisMax) at (0,9);

  % draw a path from (0,0) to (5,3)
  \path[red,thick,->] (Origin) edge (1,1) {};
  \path[red,thick,->] (1,1) edge (2,2) {};
  \path[red,thick,->] (2,2) edge (3,3) {};
  \path[red,thick,->] (3,3) edge (4,4) {};
  \path[red,thick,->] (4,4) edge (5,3) {};
\newframe
  \coordinate (Origin)   at (0,0);
  \coordinate (XAxisMin) at (0,0);
  \coordinate (XAxisMax) at (10,0);
  \coordinate (YAxisMin) at (0,0);
  \coordinate (YAxisMax) at (0,9);

  % draw a second path from (0,0) to (5,3)
  \path[purple,thick,->] (Origin) edge (1,0) {};
  \path[purple,thick,->] (1,0) edge (2,0) {};
  \path[purple,thick,->] (2,0) edge (3,1) {};
  \path[purple,thick,->] (3,1) edge (4,2) {};
  \path[purple,thick,->] (4,2) edge (5,3) {};
\newframe
  \coordinate (Origin)   at (0,0);
  \coordinate (XAxisMin) at (0,0);
  \coordinate (XAxisMax) at (10,0);
  \coordinate (YAxisMin) at (0,0);
  \coordinate (YAxisMax) at (0,9);

  % draw a third path from (0,0) to (5,3)
  \path[green,thick,->] (Origin) edge (1,1) {};
  \path[green,thick,->] (1,1) edge (2,2) {};
  \path[green,thick,->] (2,2) edge (3,3) {};
  \path[green,thick,->] (3,3) edge (4,3) {};
  \path[green,thick,->] (4,3) edge (5,3) {};
\end{animateinline}
\end{document}

相关内容