I have drawn the following tree in TikZ. What I don't like about it is
- that I have to manually adjust the
sibling distance
for each level; and - the syntax is too cumbersome.
It has been suggested to me by @percusse and @AlanMunn that using tikz-qtree
and/or forest
may be a more efficient way to produce the same result. But I don't have experience in using either package.
It would be nice if someone can reproduce my example using either of these packages, so that I can have quick example to learn from instead of reading a 150-page manual trying to find an answer.
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.2,fill=black},
hollow node/.style={circle,draw,inner sep=1.2},
}
% macro for entering payoffs
\newcommand\payoff[1]{
$\begin{pmatrix} #1 \end{pmatrix}$
}
\begin{tikzpicture}[font=\footnotesize]
\tikzset{
level 1/.style={level distance=15mm,sibling distance=65mm},
level 2/.style={level distance=15mm,sibling distance=30mm},
level 3/.style={level distance=15mm,sibling distance=15mm},
level 4/.style={level distance=15mm,sibling distance=10mm},
}
\node[hollow node,label=above:{Nature}]{}
child{node[solid node,label=left:{P1}]{}
child{node(l1)[solid node]{}
child{node[solid node,label=below:{\payoff{1\\-1}}]{}edge from parent node[left]{L}}
child{node[solid node,label=below:{\payoff{0\\0}}]{}edge from parent node[right]{R}}
edge from parent node[left]{U}
}
child{node(l2)[solid node]{}
child{node[solid node,label=below:{\payoff{0\\0}}]{}edge from parent node[left]{L}}
child{node[solid node,label=below:{\payoff{2\\-2}}]{}edge from parent node[right]{R}}
edge from parent node[right]{D}
}
edge from parent node[left,xshift=-10]{A}
}
child{node[solid node,label=right:{P1}]{}
child{node(r1)[solid node]{}
child{node[solid node,label=below:{\payoff{-2\\2}}]{}edge from parent node[left]{L}}
child{node[solid node,label=below:{\payoff{0\\0}}]{}edge from parent node[right]{R}}
edge from parent node[left]{U}
}
child{node(r2)[solid node]{}
child{node[solid node,label=below:{\payoff{0\\0}}]{}edge from parent node[left]{L}}
child{node[solid node,label=below:{\payoff{-1\\1}}]{}edge from parent node[right]{R}}
edge from parent node[right]{D}
}
edge from parent node[right,xshift=10]{B}
}
;
\draw[dashed](l1)--(l2)--node[midway,above]{P2}(r1)--(r2);
\end{tikzpicture}
\end{document}
tikz-qtree
and/orforest
. Converting the example to the[
/]
syntax might be the first thing to do …tikz-qtree
is adding the labels to the nodes and edges. I've never usedforest
before, and when I tried using\tikzset
to set my node styles, I got an error. Still reading theforest
manual trying to find out...