2

I used the code for adding overlay animations on tikz-qtree diagrams, suggested by Ignasi (tex.SE answer here). With this code, I can create the following animations:

\documentclass{beamer}

\usepackage{tikz} \usepackage{tikz-qtree}

\tikzset{% add overlay animations to qtrees 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 }, }

\begin{document} \begin{frame} \begin{tikzpicture}

        \Tree
        [.\node [visible on=&lt;1-&gt;] {Root};
            \edge [visible on=&lt;2-&gt;];\node [visible on=&lt;2-&gt;] {Leaf 1};
            \edge [visible on=&lt;3&gt;];\node [visible on=&lt;3&gt;] {Leaf 2};
        ]

    \end{tikzpicture}
\end{frame}

\end{document}

However, I don't know how to modify the code to allow for two arguments to the visible on command to produce something like this:

[visible on=<1,5-6>]

When I add a second (optional) argument to the command, I get an error that says "File ended while scanning use of \pgfkeys@code." How can I modify the code to allow for the optional second argument?

Qrrbrbirlbel
  • 119,821
Ernesto
  • 375

1 Answers1

3

A , in the value given to a key needs to be protected from the parser.

In this special case, the best would be

[visible on=<{1,5-6}>]

Usually

[visible on={<1,5-6>}]

would be good to go, too but the visible on style does the same mistake, it should be

visible on/.style={alt={#1{}{invisible}}}

but even the overlay-beamer-styles library makes the same mistake.

Though, I would use a @alt style that expects two or three braced arguments and an alt key that expects one <…> and then one or two groups.

Code

\documentclass{beamer}
\usepackage{tikz-qtree}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style args={<#1>}{@alt={#1}{}{invisible}},
    alt/.style args={<#1>#2#3}{@alt={#1}{#2}{#3}},
    @alt/.code n args={3}{\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}}}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\Tree
[.\node [visible on=<1->] {Root};
    \edge [visible on=<2->];
      \node [visible on=<2->] {Leaf 1};
    \edge [visible on=<3>];
      \node [visible on={<1,5-6>}, alt=<{1,6}>{green}] {Leaf 2};
]
\end{tikzpicture}
\end{frame}
\end{document}
Qrrbrbirlbel
  • 119,821