9

I would like to present a tree with forestin beamer, but parts after parts, starting from the bottom, and then ascent to the top.

So let's consider a simple tree like the following :

\documentclass{beamer}
\usepackage{forest}

\begin{document}

\begin{frame}
  \begin{forest}
    [VP, calign=last
      [{[ajout]}\\\textit{rapidement}, 
      align=center,
      base=top]
      [VP, calign=first
        [VP, calign=first
          [V\\\textit{mange}, align=center,base=top]
          [{[compl]}\\\textit{une orange}, align=center,base=top]
        ]
        [{[ajout]}\\\textit{dans la cuisine}, align=center,base=top]
      ]
    ]
  \end{forest}
\end{frame}

\end{document}

I would like to present the bottom of the tree first (so basically the "T" with the "mange" beneath). Then the branch above (the VP with the child on the right), then the level above, and so on until the top of the tree (I hope I'm clear).

Based on this discussion, I know how to do it the other way around (from top to bottom). But how can I do to achieve it as I described?

8

You can use visible on style defined by Qrrbrbirlbel but, instead of using it for tree, do it for ancestors'. for ancestors' style is applied to actual node and parents, therefore visible on=<1-> means this node and parents and edges between them will be visible from slide 1, but applying visible on=<2-> to parent nodes they are not visible until slide 2.

Edges between nodes and parents are also visible, but I don't know how to change slide value in style definition. The solution I can provide to show edges only when ancestors are shown is manually fix edges visibility with

[{[ajout]}\\\textit{dans la cuisine}, align=center, visible on=<2->,edge={/tikz/visible on=<3->}]

Here is the complete code

\documentclass{beamer}
\usepackage{forest}

\setbeamertemplate{navigation symbols}{} %Remove navigation bar
\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
    },
}
\forestset{
  visible on/.style={
    for ancestors'={
      /tikz/visible on={#1},
      edge={/tikz/visible on={#1}}}}}

\begin{document}
\begin{frame}[plain]{Same with forest}
  \begin{forest}
    [VP, calign=last, visible on=<4->
      [{[ajout]}\\\textit{rapidement}, 
      align=center,
      base=top, visible on=<3->, ]
      [VP, calign=first, visible on=<3->, 
        [VP, calign=first, visible on=<2->, 
          [V\\\textit{mange}, align=center,base=top, visible on=<1->, ]
          [{[compl]}\\\textit{une orange}, align=center,base=top, visible on=<1->, ]
        ]
        [{[ajout]}\\\textit{dans la cuisine}, align=center, visible on=<2->,]
      ]
    ]
  \end{forest}

\end{frame}
\end{document}

enter image description here

Note: since forest v2.0, key for ancestors' should be changed to for current and ancestors.

  • That's great! With small modifications, I've got exactly what I needed. Thank you very much ! – BonyHoax Mar 26 '14 at 9:20
  • 1
    +1 Just a small historical remark: the visible on style was originally developed by Daniel (see Mindmap tikzpicture in beamer (reveal step by step); also related, and former work, can be attributed to Matthew Leingang (see How to make beamer overlays with Tikz node). – Claudio Fiandrino Mar 27 '14 at 15:51
  • @ClaudioFiandrino: Thanks for pointing it. I was referring to visible on style applied to forest which was developed by Qrrbrbirlbel based on \tikz\visible on developed by Daniel as you mention. – Ignasi Mar 27 '14 at 16:35
  • @Ignasi: thank you for the feedback: I've just seen Qrrbrbirlbel implementation (clearly I read too much superficially). – Claudio Fiandrino Mar 27 '14 at 16:43
  • Now, three and a half years later, the for ancestors' switch appears to no longer exist, and for ancestors (without the apostrophe) produces a different output. – Pavel Rudnev Nov 12 '17 at 14:10
3

Here's a variation of Ignasi's answer which provides a show up tree style for revealing trees incrementally upwards. This style also illustrates a way to get the edges to appear with their parents when passing a single overlay specification, rather than with their children, which Ignasi suggested handling by passing two different overlay specifications.

\documentclass{beamer}
\usepackage{forest}

\setbeamertemplate{navigation symbols}{} %Remove navigation bar
\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
  },
}
\forestset{
  show up tree/.style={
    before typesetting nodes={
      tempcounta/.max={level}{tree},
      tempcounta'+=1,
      for tree={
        /tikz/visible on/.process={ ROw2+nw {tempcounta}{level}{##1-##2}{<##1->} },
        edge+/.process={ ROw2+nw {tempcounta}{level}{(##1-##2)+1} {/tikz/visible on={ {<##1->} } }},
      }
    }
  }
}

\begin{document}
\begin{frame}[plain]{Same with forest}
  \begin{forest}
    show up tree
    [VP, calign=last, 
      [{[ajout]}\\\textit{rapidement}, 
      align=center,
      base=top,  ]
      [VP, calign=first,  
        [VP, calign=first,  
          [V\\\textit{mange}, align=center,base=top,  ]
          [{[compl]}\\\textit{une orange}, align=center,base=top,  ]
        ]
        [{[ajout]}\\\textit{dans la cuisine}, align=center, ]
      ]
    ]
  \end{forest}

\end{frame}
\end{document}

<code>show up tree</code>

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.