Q: Fix node positioning for pgfonlayer to prevent shaky gif 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}



A: You can define a bounding box that is as large as the picture with both arrows adding something like to your code:
\useasboundingbox (-1,-2) rectangle (10,2);

You can also make use of the overlay-beamer-styles that allows you to make certain paths of the picture invisible or visble on different slides.
\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}


Note that the arrows library is deprecated and you should probably use the newer arrows.meta library.
