# Beamer overlay specifications for a tikzpicture

Overlay specifications can be added to the TikZ commands.

\node<2> (a) {only visible on slide 2};


Is this also possible for the whole tikzpicture environment?

\begin{tikzpicture}[<2>]
\node (a) {only visible on slide 2};
\node (b) {also only visible on slide 2};
\end{tikzpicture}


This can be emulated by enclosing the environment in \only<2>{ ... } but this is impossible when the tikzpicture is used in a \newenvironment.

• A quick solution is to include \only<2> in the definition of your new environment, unless you have a more specific example in mind that doesn't work with this strategy. – Herr K. Nov 25 '13 at 22:33
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jub0bs Dec 8 '13 at 18:51

As usual, these problems can be easily solved thanks to the style visible on defined by Daniel (see Mindmap tikzpicture in beamer (reveal step by step)).

Moreover, it works without problems with custom environments. Demonstration:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}

\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}

\newenvironment{mytikz}[1][]{\begin{tikzpicture}[#1]}{\end{tikzpicture}}

\begin{document}
\begin{frame}
\begin{tikzpicture}[visible on=<2->]
\node at (0,0) (a) {only visible on slide 2};
\node at (2,2) (b) {also only visible on slide 2};
\end{tikzpicture}

Some text here:
\begin{itemize}
\item one
\item two
\end{itemize}

\begin{center}
\begin{mytikz}[visible on=<3>]
\draw[top color=orange,bottom color=magenta!80!purple]
(0,0) rectangle(2,1);