Presenting a {forest} tree from bottom to top in beamer
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}
Note: since forest v2.0
, key for ancestors'
should be changed to for current and ancestors
.
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}