I've got this:
\documentclass{article}
\usepackage{forest,tikz}
\forestset{
ptree/.style={
for tree={
grow'=east, %grow' reverses direction of reading...for horizontal to the right, use it
l=2.5cm, %length of the branches
%s sep=1em, %spreads out ends of branches
parent anchor=children,
child anchor=west,
anchor=west, %child anchor west w/ anchor west lines up words on left edge
% calign=first %to match tree tab of Workbooks
},
before typesetting nodes={
for tree={
split option={content}{:}{content, my edge label},
},
},
},
my edge label/.style={
if={n_children("!u")>2
}{edge label={node [pos=.55, above=2ex, font=\footnotesize,draw,anchor=center] {#1} }%true
}{%false
if={ > O_= {n'}{1} }
{ edge label={node [pos=.55, below=.5ex, font=\footnotesize] {#1} }
}{
edge label={node [pos=.55, above=.5ex, font=\footnotesize] {#1} }
},
}%end false
}%end style
}%end forestset
\begin{document}
\pagestyle{empty}
Looks good with decimals above:
\begin{forest}
ptree
[[W:.5[W][L]][L:.5[W][L]]]
\end{forest}
\begin{forest}
ptree
[[A:0.1[Def:.3][Good:.7]]
[B:0.3[Def:.03][Good:.97]]
[C:0.6[Def:.02][Good:.98]]]
\end{forest}
\end{document}
Which uses code from Horizontal Probability Tree using Forest with Edge Labels
For two branches, amazing! (first forest) For three branches, the .3 on the middle branch is set too high (second forest).
I'd like the edge labels the same orthogonal distance from the lines AND not sloped, and actually numbers always above the lines would be fine. I'd also like them all at the same horizontal position (thus the pos=.55), so "auto" doesn't work (as it changes the horizontal alignment).
I'm super new to forest, and I know I could do this manually with tikz. I'm hoping someone knows an easy fix to get labels per level at the same position horizontally with the vertical position determined by the orthogonal distance of the closest point of the text to the line it is labelling.
Thank you for any help!
EDIT: Is there some way to control n children OR n_children in the edge label so that it is above for 3 or more branches & AS IS for 2? (I'm having syntax issues on the "control" in forest.)
EDIT: -- I solved this... if={n_children("!u")>2} as the condition.
I'd still like to know how to keep the orthogonal distance identical, as the middle branch's edge label seems too high when the slanted branches' labels look good.

my edge label/.style={ if={ > O_= {n'}{1} }{ edge label={node [pos=.55, below, font=\footnotesize, sloped] {#1} } }{ edge label={node [pos=.55, above, font=\footnotesize, sloped] {#1} } }, }– Zarko Oct 07 '21 at 18:08