Forest: classic decision tree
like this?
edit: an attempt to make tree code slightly shorter
- from preamble of your mwe is relevant only package
forest
- styles of nodes and edges labels are defined as
for tree
options - style for labels is moved in
forest
environment - to tree code are added comments for short its explanation
\documentclass[margin=3mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
/tikz/every label/.append style={xshift=-1pt,inner sep=1pt,font=\footnotesize},
for tree={
grow'=east,
% node style
line width=0.4pt,
minimum size=2pt,
inner sep=2pt,
if n children=0{}{draw}, % <--- added
% anchors <------- solve basic problem
parent anchor=children,
child anchor=parent,
% distances of nodes
l sep=17mm, % <-- *l*: level distance
s sep=2mm, % <-- *s*: sibling distance between leaves
% edges
edge={draw},
edge path'={
(!u.parent anchor) -- ([xshift=-13mm].child anchor) -- (.child anchor)
},
% labels on edges
delay={
edge label/.wrap value={node[midway, inner sep=1pt,
font=\scriptsize, above]{#1}},
},
}, % end for tree
[ , label=$n_0$
[, label=$n_3$, edge label={$s_5,s_6$}
[$o_6$, edge label={$s_6(n_3)$}]
[$o_5$, edge label={$s_5(n_3)$}]
]
[ , label=$n_2$, edge label={$s_3,s_4$}
[$o_4$, edge label={$s_4(n_2)$}]
[$o_3$, edge label={$s_3(n_2)$}]
]
[ , label=$n_1$, edge label={$s_1,s_2$}
[$o_2$, edge label={$s_2(n_1)$}]
[$o_1$, edge label={$s_1(n_1)$}]
]
]
\end{forest}
\end{document}