我想使用 tikz 创建 gif。但是,使用pgfonlayer
创建多个页面会导致节点在它们之间添加边时发生移动。这会使 gif 非常不稳定。
有没有办法“锁定”这 9 个节点,以便这些节点之间的箭头能够顺利显示在 gif 中?
这是正在创建的 2 个页面的工作示例,但它们未正确对齐。
\documentclass[hyperref={pdfpagelabels=false}]{beamer}
\usepackage{lmodern}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\tikzstyle{box}=[rectangle, draw, thick, minimum size=6mm]
\tikzstyle{up_arrow}=[->, shorten >= 1pt, >=stealth',semithick,bend left]
\tikzstyle{down_arrow}=[->, shorten >= 1pt, >=stealth',semithick,bend right]
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{frame}
\begin{figure}
\begin{tikzpicture}[bend angle=45][overlay]
\node[box] [label=below:{0}] (a0) {a};
\node[box] [label=below:{1}] (a1) [right of=a0] {b};
\node[box] [label=below:{2}] (a2) [right of=a1] {c};
\node[box] [label=below:{3}] (a3) [right of=a2] {a};
\node[box] [label=below:{4}] (a4) [right of=a3] {d};
\node[box] [label=below:{5}] (a5) [right of=a4] {d};
\node[box] [label=below:{6}] (a6) [right of=a5] {c};
\node[box] [label=below:{7}] (a7) [right of=a6] {a};
\node[box] [label=below:{8}] (a8) [right of=a7] {c};
\node[box] [label=below:{9}] (a9) [right of=a8] {d};
\begin{pgfonlayer}{background}
\draw<1-> [down_arrow] [draw=purple] (a6) to (a8);
\draw<2-> [up_arrow] [draw=blue] (a5) to (a9);
\end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
答案1
您可以定义一个与图片一样大的边界框,并带有两个箭头,在代码中添加类似内容:
\useasboundingbox (-1,-2) rectangle (10,2);
您还可以利用此overlay-beamer-styles
功能使图片的某些路径在不同的幻灯片上不可见或可见。
\documentclass[hyperref={pdfpagelabels=false}]{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\tikzstyle{box}=[rectangle, draw, thick, minimum size=6mm]
\tikzstyle{up_arrow}=[->, shorten >= 1pt, >=stealth, semithick, bend left]
\tikzstyle{down_arrow}=[->, shorten >= 1pt, >=stealth, semithick, bend right]
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{frame}
\begin{figure}
\begin{tikzpicture}[bend angle=45]
\node[box] [label=below:{0}] (a0) {a};
\node[box] [label=below:{1}] (a1) [right of=a0] {b};
\node[box] [label=below:{2}] (a2) [right of=a1] {c};
\node[box] [label=below:{3}] (a3) [right of=a2] {a};
\node[box] [label=below:{4}] (a4) [right of=a3] {d};
\node[box] [label=below:{5}] (a5) [right of=a4] {d};
\node[box] [label=below:{6}] (a6) [right of=a5] {c};
\node[box] [label=below:{7}] (a7) [right of=a6] {a};
\node[box] [label=below:{8}] (a8) [right of=a7] {c};
\node[box] [label=below:{9}] (a9) [right of=a8] {d};
\begin{pgfonlayer}{background}
\draw[visible on=<1->, down_arrow] [draw=purple] (a6) to (a8);
\draw[visible on=<2->, up_arrow] [draw=blue] (a5) to (a9);
\end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
请注意,该arrows
库已被弃用,您可能应该使用较新的arrows.meta
库。