Beamer overlays in tikz-network figures

I would like to define overlays (in the Beamer sense) in figures designed using the tikz-network package.

For instance, say I have the following figure:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-network}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\Vertex[x=0.0, y=1.0, label=$v_1$]{v1}
\Vertex[x=1.0, y=1.0, label=$v_2$]{v2}
\Vertex[x=2.0, y=1.0, label=$v_3$]{v3}

\Edge[color=black](v1)(v2)
\Edge[color=black](v2)(v3)
\end{tikzpicture}
\end{frame}
\end{document}


and that I want node v1 to disappear at step 2. I have tried using the visible on key proposed here: https://tex.stackexchange.com/a/136166/31360 and which looks like this:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tikz-network}

\tikzset{
invisible/.style={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
},
}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\Vertex[x=0.0, y=1.0, label=$v_1$, visible on=<2->]{v1}
\Vertex[x=1.0, y=1.0, label=$v_2$]{v2}
\Vertex[x=2.0, y=1.0, label=$v_3$]{v3}

\Edge[color=black](v1)(v2)
\Edge[color=black](v2)(v3)
\end{tikzpicture}
\end{frame}
\end{document}


But it does not seem to work with tikz-network, as I get a "Package xkeyval Error: 'on visible' undefined in families 'vertex'" error. I guess the solution is to extend the key to vertex (and to edge as well), but I do not know how to do that.

• Please add a full compileable code. – AndréC Oct 30 '19 at 20:29
• Sorry, I completed my question. – Vincent Labatut Oct 30 '19 at 20:42
• To make use of \alt, you need in one way or another involve beamer. And you need to switch to the tikz directory with \Vertex[x=0.0, y=1.0, label=$v_1$,style={visible on=<2->}]{v1}. – user194703 Oct 30 '19 at 21:00
• Indeed, I forgot to include the beamer code when I wrote the minimal example, my bad. I fixed that in the question. About your above solution: it works fine...except for the text, which is still displayed when the rest of the node isn't. – Vincent Labatut Oct 31 '19 at 8:15

Not knowing the tikz-network package, I don't know if it is possible to adapt the visible on style for tikz-network. Nevertheless, it is still possible to use the classic controls for overlaying with beamer.

To do this, you must place yourself in a frame environment (which you have forgotten). The commands \onslide and \only are identical except that \onslide reserves the place of what it does not display.

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tikz-network}

%  \tikzset{
%    invisible/.style={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
%    },
%  }
\begin{document}
\begin{frame}
\begin{tikzpicture}
\onslide<1->{\Vertex[x=0.0, y=1.0, label=$v_1$]{v1}}
\onslide<2->{\Vertex[x=1.0, y=1.0, label=$v_2$]{v2}}
\onslide<3->{\Vertex[x=2.0, y=1.0, label=$v_3$]{v3}}

\only<2->{\Edge[color=black](v1)(v2)}
\only<3>{\Edge[color=black](v2)(v3)}
\end{tikzpicture}
\end{frame}

\end{document}


Translated with www.DeepL.com/Translator

• Indeed, I had forgotten to put the figure in a beamer document in my question. I have corrected that. Thanks for your answer! – Vincent Labatut Oct 31 '19 at 8:19

If you switch to beamer, you can make of the \alt command that the TikZ styles you are trying to employ are using. Unfortunately, tikz-network has its own keys for opacity, so you could do something like the following:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tikz-network}

\begin{document}
\begin{frame}[t]
\frametitle{A network}
\begin{tikzpicture}
\begin{scope}
\alt<2->{}{\def\VertexFillOpacity{0}\def\VertexLineOpacity{0}
\def\VertexTextOpacity{0}}
\Vertex[x=0.0, y=1.0, label=$v_1$]{v1}
\end{scope}
\Vertex[x=1.0, y=1.0, label=$v_2$]{v2}
\Vertex[x=2.0, y=1.0, label=$v_3$]{v3}

\Edge[color=black](v1)(v2)
\Edge[color=black](v2)(v3)
\end{tikzpicture}
\end{frame}
\end{document}


Or, with the edge also disappearing and a style.

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tikz-network}
\tikzset{
network invisible/.code={\def\VertexFillOpacity{0}\def\VertexLineOpacity{0}\def\VertexTextOpacity{0}
\def\EdgeOpacity{0}\def\EdgeTextFillOpacity{0}\def\EdgeTextOpacity{0}},
network visible on/.code={\alt#1{}{\tikzset{network invisible}}}}
\begin{document}
\begin{frame}[t]
\frametitle{A network}
\begin{tikzpicture}
\begin{scope}[network visible on=<2->]
\Vertex[x=0.0, y=1.0, label=$v_1$]{v1}
\end{scope}
\Vertex[x=1.0, y=1.0, label=$v_2$]{v2}
\Vertex[x=2.0, y=1.0, label=$v_3$]{v3}
\begin{scope}[network visible on=<2->]
\Edge[color=black](v1)(v2)
\end{scope}
\Edge[color=black](v2)(v3)
\end{tikzpicture}
\end{frame}
\end{document}


• Let me also mention that the visible on style was invented for a reason: you can use the vertices in paths even when they are not shown, and you are not haunted by jumps in the slides. – user194703 Oct 30 '19 at 21:39
• Thanks for your answer! I do not need to draw paths, so I think I'll use AndréC's solution, though, as I find it is less verbose. – Vincent Labatut Oct 31 '19 at 8:22
• @VincentLabatut tikz-network adds a lot of paths, so sooner or later you may experience jumps. There is a very long analogous story in the context of ordinary tikzpictures. – user194703 Oct 31 '19 at 14:53