6

I would like to change a property, say the color, of a forest node between overlays in beamer. It is proposed elsewhere to use PGF's keys for this in the general case. However, this approach doesn't seem to be compatible with forest, at least this is what I experience. The following MWE does not compile:

\documentclass{beamer}
\usepackage{forest}

\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}} 
}}

\begin{document}
\begin{frame}

\begin{forest}
[A,name=a [B,name=b,onslide=<2>{red}] [C,name=c] ]
\end{forest}

\end{frame}
\end{document}

I could equally well live with a solution along the following lines:

\documentclass{beamer}
\usepackage{forest}

\begin{document}
\begin{frame}

\begin{forest}
[A,name=a [B,name=b] [C,name=c] ]
\only<2>{
    %add parameter red to node b
}
\end{forest}

\end{frame}
\end{document}

Any idea how to achieve this?

Edit: Thanks to @cfr for making me aware of the stupid bug in my MWE. \tikzset was located inside the forest environment.

  • Did this solve it for you? I didn't have too much time earlier, so I just really tested your code to make sure I could reproduce, copied the stuff I was using and tested it to make sure it worked, and posted the result. I didn't really try to diagnose the problem. (\tikzset can usually come after \begin{document} and not only in the preamble, although there are some exceptions to this.) – cfr Jul 2 '15 at 20:19
  • @cfr: Yes, I'm really happy with it :) The problem with \tikset popped up when putting it inside the forest environment (contrary to what I said first). That's probably not so unexpected. – Timm Jul 2 '15 at 21:00
  • Oh, right. Yes. That would be likely to cause problems. You can say /tikz/whatever/.style={...} etc. after \begin{forest} but it is already primed to set forest keys at that point, so a \tikzset (or a \forestset) is not likely to go down well ;). – cfr Jul 2 '15 at 21:19
5

This code is originally adapted from various answers by other people. It is what I'm currently using for this kind of thing. Hopefully it will help you too.

\documentclass{beamer}
\usepackage{forest}
\tikzset{% set up for transitions using tikz with beamer overlays
  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
  },
  transparent/.style={opacity=0.1,text opacity=0.1},
  opaque on/.style={alt=#1{}{transparent}},
  alerted/.style={color=alerttextdefaultfg},
  alert on/.style={alt=#1{alerted}{}},
}
\forestset{%
  visible on/.style={%
    for tree={%
      /tikz/visible on={#1},
      edge={/tikz/visible on={#1}}}},
  opaque on/.style={%
    for tree={%
      /tikz/opaque on={#1},
      edge={/tikz/opaque on={#1}}}},
  alerted on/.style={%
    for tree={%
      /tikz/alerted on={#1},
      edge={/tikz/alerted on={#1}}}},
}
\begin{document}
\begin{frame}

\begin{forest}
  [A,name=a [B,name=b,alt=<2>{red}{}] [C,name=c] ]
\end{forest}

\end{frame}
\end{document}

trees

Obviously you don't need all of the styles I show, but I included them for completeness as you can easily delete them if they are unwanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.