1

I would like for the nodes of my forest to be visible sequentially. The code below makes the text sequential, but still shows the boxes for each item. How can I make it so the boxes and text appear sequentially?

Here's my mwe:

\documentclass[xcolor={dvipsnames}]{beamer}
\usepackage{tikz}
\usepackage{forest}
\usepackage{pgfkeys}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{frame}

\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}} }, block/.style={rectangle, draw, fill=white!20, text width=2.75cm, text centered, rounded corners, minimum height=1.4cm}, line/.style={draw, very thick, color=black!80, -Stealth}, }

\forestset{ visible on/.style={ for tree={ /tikz/visible on={#1}, edge+={/tikz/visible on={#1}}}}}

\begin{forest} arrow to/.style n args=2{% delay={% tikz+={% \draw [every edge, line] () -- (!#1) node [above, midway] {#2}; }, }, !u.s sep+=30pt, }, before typesetting nodes={% where n=1{% edge label/.wrap value={% node [left,pos=.75, anchor=mid east] {#1} }, }{% edge label/.wrap value={% node [right,pos=.75, anchor=mid west] {#1} }, }, }, for tree={% grow=east, parent anchor=east, child anchor=west, calign=edge midpoint, edge+=->, block, edge={line}, l sep+=10pt, }, forked edges [\visible<1->{some text} [\uncover<2->{some more text} [\uncover<3->{even more text}] [\uncover<3->{more text again}] [\uncover<3->{even some more text}]

]
[\uncover&lt;2-&gt;{the last text}
]

] \end{forest}

\end{frame} \end{document}

Thank you!

Updated the code: Thanks for pointing out it didn't compile. There was an extra { I removed.

Code from: Positioning and layout in Forest

krw
  • 11
  • 2
    Your codes does not seem to compile. – samcarter_is_at_topanswers.xyz Oct 11 '23 at 15:13
  • Why are you not using the styles you've defined i.e. visible on etc.? Also, please include a link if you used code you found elsewhere. I can track it down, but it's easier if you link and, if it is from SE, the licence requires it (unless the author has dual-licensed it). – cfr Oct 11 '23 at 15:16
  • Here's the link I started with: https://tex.stackexchange.com/questions/322261/positioning-and-layout-in-forest – krw Oct 11 '23 at 15:29
  • I see that my forest set styles are not actually doing any thing. If I get rid of that code, what should I use instead? Thank you again. – krw Oct 11 '23 at 15:32

1 Answers1

1

Your code fails to compile due to multiple errors. Whenever you get an error, the PDF which results is good only for debugging. It is not expected to be as you'd expect if compilation succeeded. It's fine to post code which won't compile if you can't fix it. But please report the error!

It's not clear to me from your code what exactly you're trying to do.

  • You use forked edges but don't load the library it requires.
  • You define visible on etc. but don't use them.
  • You define arrow to, but never use it.
  • You include code for positioning edge labels you don't have.

In addition, you have mismatched { }, a blank line in your forest environment, incorrect use of parameters in definitions and miscellaneous other mistakes. All of these have to be corrected before you can decide if the output is correct or not.

Here's a version which compiles. I've left the unused definition of arrow to, but commented out the edge label handling, since that won't work as-is. I've replaced \visible and \uncover by visible on, corrected the { } groups and removed the blank line. I've also moved the remaining definitions to the preamble, so they can be reused without duplication, added the edges library and removed the loading of packages used by forest anyway.

uncovering a forest tree in Beamer

\documentclass[xcolor={dvipsnames}]{beamer}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\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}} 
  },
  block/.style={rectangle, draw, fill=white!20, text width=2.75cm, text centered, rounded corners, minimum height=1.4cm},
  line/.style={draw, very thick, color=black!80, -Stealth},
}

\forestset{ visible on/.style={ for tree={ /tikz/visible on={#1}, edge+={/tikz/visible on={#1}}, }, }, arrow to/.style n args=2{% delay={% tikz+={% \draw [every edge, line] () -- (!#1) node [above, midway] {#2}; }, }, !u.s sep+=30pt, }, }

\begin{document}

\begin{frame}

\begin{forest} % before typesetting nodes={% % where n=1{% % edge label/.wrap value={% % node [left,pos=.75, anchor=mid east] {#1} % }, % }{% % edge label/.wrap value={% % node [right,pos=.75, anchor=mid west] {#1} % }, % }, % }, for tree={% grow=east, parent anchor=east, child anchor=west, calign=edge midpoint, edge+=->, block, edge={line}, l sep+=10pt, }, forked edges [some text, visible on=<1-> [some more text, visible on=<2-> [even more text, visible on=<3->] [more text again, visible on=<3->] [even some more text, visible on=<3->] ] [the last text, visible on=<2-> ] ] \end{forest}

\end{frame} \end{document}

cfr
  • 198,882
  • 1
    Thank you so much. This is very helpful.I have a couple questions so I can better understand how it's working. So, in the tikzset code, are we defining what the nodes look like both when visible, and when not visible? Then the forestset code outlines when elements including the edges appear? Per your suggestion, I removed the arrow to code from the forest set code, as you pointed out it's not necessary. Just to see how it worked, when I commented the entire forest set lines, the arrows showed up, but not the edges. Again, thank you so much. – krw Oct 11 '23 at 16:50
  • @KariWaters Ah, your comment changed while I was writing mine. Yes, the \forestset defines a style such that the stuff defined in \tikzset gets applied to the edge as well as the node. Then <content>, visible on=<overlay specification> applies the style to the node and the edge for that node. Basically, otherwise you get the edges appearing even though the nodes are invisible which looks odd. I've used basically this code a reasonable amount in Beamer and it works provided I think about it ;). – cfr Oct 11 '23 at 16:54