I'd like to create a gif using tikz. However, using the pgfonlayer to create multiple pages results in the nodes being shifted whenever an edge is added between them. This makes the gif very shaky.
Is there a way to "lock down" the 9 nodes, so that arrows between these nodes appear smoothly in a gif?
This is a working example of 2 pages being created, but they are not correctly aligned.
\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}


tikzpicture. Try adding something like\useasboundingbox (0,1.25);right before\end{tikzpicture}. This increases the upper bound of the bouding box and should prevent shifting. – Jasper Habicht Aug 16 '22 at 08:37useasboundingboxso that I can explore other fine tuning options? – adaptatron Aug 16 '22 at 08:56\useasboundingboxjust takes any path. You can use a rectangle that is large enough to fit all elements of your picture. – Jasper Habicht Aug 16 '22 at 09:02