# TikZ drawing order when using animate

I've have a problem when I use animations in TikZ images:

I like draw a figure over another figure by

\path(fig) node[anchor = north, inner sep=0pt,outer sep=5pt] {
FIGURE1
}

\path(fig) node[anchor = north, inner sep=0pt,outer sep=5pt] {
FIGURE2 over FIGURE1
}


This works fine until I use an animation:

\path(fig) node[anchor = north, inner sep=0pt,outer sep=5pt] {
\begin{animateinline}[loop,autoplay]{2}
\multiframe{8}{ipic=1+1}{
FIGURE1_\ipic
}
\end{animateinline}
}

\path(fig) node[anchor = north, inner sep=0pt,outer sep=5pt] {
FIGURE2 over FIGURE1
}


The first FIGURE1 is now animated but FIGURE2 is beneath FIGURE1. Using pgfonlayer/background doesn't help. Does anyone have an idea?

Here is a simple example. In the second frame, the animated background appears, but it should remain beneath the blue block. The only solution I know is to put the "animateinline"-environment around the entire tikz picture, but this is not what I want.

\documentclass{beamer}

\usepackage{animate}
\usepackage{tikz}

\begin{document}
\begin{frame}

\centering
\begin{tikzpicture}

\path (0,0) node[anchor = north] {%
BACKGROUND
};

\path (0,0) node[anchor = north,fill=blue] {%
\color{red}HOLLA DIE WALDFEE OVERLAY
};

\end{tikzpicture}

\end{frame}

\begin{frame}

\centering
\begin{tikzpicture}

\path (0,0) node[anchor = north,fill=green] {%
\begin{animateinline}[loop,autoplay]{2}
\multiframe{8}{inum=1+1}{
\color{green}\bf BACKGROUND \inum
}
\end{animateinline}
};

\path (0,0) node[anchor = north,fill=blue] {%
\color{red}HOLLA DIE WALDFEE OVERLAY
};

\end{tikzpicture}

\end{frame}

\end{document}

• Welcome to TeX.SX! You can have a look on our our starter page to familiarize yourself further with our format. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. – Claudio Fiandrino Jun 26 '13 at 10:12
• I see. You want an animated background and something static in the foreground. But animate-generated animations are implemented via PDF annotations (interactive regions). However, PDF annotations don't belong to the page content like normal text/graphics, but live in a separate layer above the page. Thus, they are always in the foreground. Everything you want to appear in front of animated content must itself be part of the animation. – AlexG Jun 26 '13 at 12:04

UPDATE

By default, animate-generated animations are implemented as PDF Widget annotations (interactive regions), which live in a separate layer above the normal page content. They are therefore always rendered in the foreground.

The current [20140923] version of animate allows using an alternative animation method based on PDF Layers (OCG s) whose content is directly embedded in the page content and thus honours the drawing (or Z-)order of graphical objects.

Note, that the default Widget-based animation method usually performs better with increasing complexity of the graphics.

Put option useocg either as package or command option. It allows for animations placed in the page background:

\documentclass{beamer}

\usepackage[useocg]{animate}[20140923]
\usepackage{tikz}

\begin{document}

\begin{frame}

\centering
\begin{tikzpicture}

\path (0,0) node[anchor = north,fill=green] {%
\begin{animateinline}[loop,autoplay]{2}
\multiframe{8}{inum=1+1}{
\bf BACKGROUND \inum
}
\end{animateinline}
};

\path (0,0) node[anchor = north,fill=blue,fill opacity=0.8] {%
TEXT TO APPEAR IN THE FOREGROUND
};

\end{tikzpicture}

\end{frame}

\end{document}

• Thanks! Now, I understand how it works. For the command animategraphics, it would have been very convenient if the ordering would be preserved. – Ben Jun 26 '13 at 12:41
• @Ben: \animategraphics behaves similarly, that is, always in the forground. – AlexG Jun 26 '13 at 13:01