I'm trying to replicate the following tree using forest.
And here's what I got
Aside from the slightly misplaced labels Pass, which I can tweak by passing elo={xshift=<n>pt,yshift=<n>pt to the relevant branches, I'm more interested in getting the directions/angles of the branches right.
Ideally, I'd like
- the
Takebranches to all grow at-90degrees (not slightly more, and non-parallel, as they currently are), and - the
Passbranches to grow at0degree (I'm now able to get this by manually puttingbefore computing xy={l=0,s=15mm}to everyone of them, a solution given in this answer, but I'd like to know a less cumbersome solution if one exists).
MWE
\documentclass[border=2pt]{standalone}
\usepackage{forest}
\forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={\draw[#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut\unexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=0mm,l=15mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
/tikz/font=\footnotesize,
},
anchors=south,
dot={fill=white},for descendants={dot={fill}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
\begin{document}
\begin{forest}
game tree
[A,
[Take;{(4,2)},]
[Pass;B,before computing xy={l=0,s=15mm},elo={xshift=-10pt,yshift=5pt}
[Take;{(2,8)}]
[Pass;A,before computing xy={l=0,s=15mm}
[Take;{(16,4)}]
[Pass;B,before computing xy={l=0,s=15mm}
[Take;{(8,32)}]
[Pass;{(64,16)},before computing xy={l=0,s=15mm}]
]
]
]
]
\end{forest}
\end{document}
Edit
After some fooling around, I managed to get the angles right (by basically specifying before computing xy for every branch). But the way I did it seemed so excessively hackish that it almost made forest lose its appeal: automatic positioning nodes to avoid overlaps. I could've drawn the tree in TikZ with this amount of code.
\begin{forest}
game tree
[A,
[Take;{(4,2)},before computing xy={l=15mm,s=0mm}]
[Pass;B,before computing xy={l=0,s=15mm},elo={xshift=-10pt,yshift=5pt},anchors=south
[Take;{(2,8)},before computing xy={l=15mm,s=0mm}]
[Pass;A,before computing xy={l=0,s=15mm},elo={xshift=-10pt,yshift=5pt},anchors=south
[Take;{(16,4)},before computing xy={l=15mm,s=0mm}]
[Pass;B,before computing xy={l=0,s=15mm},elo={xshift=-10pt,yshift=5pt},anchors=south
[Take;{(8,32)},before computing xy={l=15mm,s=0mm}]
[Pass;{(64,16)},before computing xy={l=0,s=15mm},elo={xshift=-10pt,yshift=5pt}]
]
]
]
]
\end{forest}
I'm still looking for a more efficient way to accomplish this.





forestright tool for this relatively simple image? I'm pretty sure that drawing with puretikzis far simpler. – Zarko Mar 10 '17 at 20:32forest(with the setting in the preamble of my MWE) is the most efficient way for the majority of them. So I'd prefer not to leave theforestframework if there is a better way to do this. – Herr K. Mar 10 '17 at 20:37forestas you are :) and complexity of OP MWE scare me :-(. – Zarko Mar 10 '17 at 21:50