I defined a /forest/visible on
option that passes its argument to
/tikz/visible on
to affect the actual node,
- and
/forest/edge
(this is the reason we need a visible on
option in the /forest
tree).
I asume you also want all following children (and their edges) to be invisible that's why we actually use for tree
(meaning the subtree).
Other useful options are for children
, for descendants
, …; see section 3.3.6 Propagators of the forest
manual for reference.
In this example we can use the /forest
style visible on
in a for children
option of the parent node of subcategorized
and another subcategory
. (You may re-define/add various styles so that you can hide
- only the current node (and its edges),
- only the children of the current node (and their edges), and
- the current node and its children (and its and/or their edges).
Code
\documentclass[xcolor={table, dvipsnames}]{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 tree={
/tikz/visible on={#1},
edge+={/tikz/visible on={#1}}}}}
\begin{document}
\begin{frame}[plain]{Same with forest}
\begin{forest} baseline, for tree={draw,ellipse,align=center}
[Picture root
[First level class,fill=yellow,for children={visible on=<2->}
[subcategorized,fill=gray]
[another subcategory
[last node division,fill=gray]
[in two classes,fill=gray]
]
]
[Another long category,fill=gray]
]
\end{forest}
\end{frame}
\end{document}
Output
Here are a few examples of your tree in various directions, using the istgame
package. You can use \setistgrowdirection
or its swap version \setistgrowdirection'
to change the tree growing direction.
(I drew the game tables using the tabu
package, because (as mentioned in the manual) the sgame
package is not compatible with the memoir
class or any other packages that load array.sty
.)
\documentclass{article}
\usepackage{istgame}
\usepackage{tabu,makecell,multirow}
\DeclareExpandableDocumentCommand\xcol{mO{c}m}{\multicolumn{#1}{#2}{$#3$}}
\def\gameX{%
\mbox{%
\begin{tabu}spread0pt{X[c1]X[$c1]*2{|X[$c2]}|}
\xcol2{} & \xcol2{P_2} \\
\xcol2{} & \xcol1{X} &\xcol1{Y} \\\tabucline{3-}
\multirowcell{2}{$P_1$}
& X & 1,1,1 & 2,0,2 \\\tabucline{3-}
& Y & 0,2,0 & 2,2,2 \\\tabucline{3-}
\end{tabu}%
}
}
\def\gameY{%
\mbox{%
\begin{tabu}spread0pt{X[c1]X[$c1]*2{|X[$c2]}|}
\xcol2{} & \xcol2{P_2} \\
\xcol2{} & \xcol1{X} &\xcol1{Y} \\\tabucline{3-}
\multirowcell{2}{$P_1$}
& X & 3,1,3 & 2,2,2 \\\tabucline{3-}
& Y & 1,1,1 & 1,3,1 \\\tabucline{3-}
\end{tabu}%
}
}
\pagestyle{empty}
\begin{document}
\begin{itemize}
\item a tree: downward
\begin{istgame}
\xtdistance{15mm}{50mm}
\istroot(0)[initial node]{$P_3$}
\istb{X}[al]{\gameX}[below,xshift=-8mm]
\istb{Y}[ar]{\gameY}[below,xshift=-8mm]
\endist
\end{istgame}
\item a tree: upward
\begin{istgame}
\setistgrowdirection'{north}
\xtdistance{15mm}{50mm}
\istroot(0)[initial node]<-90>{$P_3$}
\istb{X}[bl]{\gameX}
\istb{Y}[br]{\gameY}
\endist
\end{istgame}
\item a tree: toward the right
\begin{istgame}
\setistgrowdirection'{east}
\xtdistance{20mm}{15mm}
\istroot(0)[initial node]<180>{$P_3$}
\istb{X}[al]{\gameX}[above right,yshift=-2mm]
\istb{Y}[bl]{\gameY}
\endist
\end{istgame}
\end{itemize}
\end{document}
Added: You can draw the strategic games as you like. For example, if you prefer using the tabular
environment (to tabu
), replace the \def\gameX
and \def\gameY
parts above by the following:
\def\gameX{%
\mbox{%
\begin{tabular}{cc|c|c|}
\xcol2{} & \xcol2{P_2} \\
\xcol2{} & \xcol1{X} &\xcol1{Y} \\\cline{3-4}
\multirowcell{2}{$P_1$}
& X & 1,1,1 & 2,0,2 \\\cline{3-4}
& Y & 0,2,0 & 2,2,2 \\\cline{3-4}
\end{tabular}%
}
}
\def\gameY{%
\mbox{%
\begin{tabular}{cc|c|c|}
\xcol2{} & \xcol2{P_2} \\
\xcol2{} & \xcol1{X} &\xcol1{Y} \\\cline{3-4}
\multirowcell{2}{$P_1$}
& X & 3,1,3 & 2,2,2 \\\cline{3-4}
& Y & 1,1,1 & 1,3,1 \\\cline{3-4}
\end{tabular}%
}
}
Best Answer
Note that there is a package,
istgame
, which specializes on game trees. For general trees,forest
is a very powerful tool. It allows you to draw your tree very easily.