I would like to have arrows with text (above or below the arrow) connecting the nodes in a forest-environment. Unfortunately, I do not know how to implement it in the code because each arrow should have another text.
I am really grateful for every kind of help. Please find below my code:
\pgfkeys{/forest,
my rounded corners/.append style={rounded corners=2pt},
}
\begin{forest}
for tree={
font=\sffamily,
line width=1pt,
draw=linecol,
drop shadow,
fit=rectangle,
edge={thick, color=linecol, >={Triangle[]}, ->},
where level=0{%
l sep+=5pt,
calign=child,
calign child=2,
inner color=ocre!70,
outer color=ocre!70,
align=center,
my rounded corners,
for descendants={%
calign=first,
},
}{%
where level=1{%
inner color=ocre!30,
outer color=ocre!30,
my rounded corners,
align=center,
parent anchor=south west,
tier=three ways,
for descendants={%
child anchor=west,
parent anchor=west,
align=left,
anchor=west,
inner color=ocre!10,
outer color=ocre!10,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=three ways.parent anchor) |-
(.child anchor)\forestoption{edge label};
},
},
}{}%
},
}
[a
[b
[b1
[b2]
]
]
[c
[c1
[c2
[c3]
]
]
]
[d
[d1
[d2]
]
]
[e
[e1
[e2]
]
]
]
\end{forest}
Best Answer
I'm guessing here on multiple fronts: how to complete your code; what you are trying to do; what the problem is. I suspect you found this code elsewhere. If so, you should attribute it and it would be helpful to have a link. (Hopefully, the original example is complete.)
I've substituted colours as I don't know how yours are defined. I've added libraries and I've tried to simplify things where possible.
I think you want something like this:
If so, then I recommend using the
folder
style from Forest'sedges
library, which makes life a lot easier when drawing this kind of tree.Forest has a built-in key for adding labels to the edges called
edge label
.arrow label
is a simple wrapper.Note that you should not use
where
within the scope of eitherfor tree
or anotherwhere
aswhere
implicitly usesfor tree
itself. Useif
or take thewhere
outside the scope. Here, I take the first conditional outside the scope offor tree
and change the second, which needs to be within the scope of the first, toif
.Saying
inner color=<colour>, outer color=<colour>
is pointless if<colour>
is the same. All it does is slow compilation.fill=<colour>
is better in this case.I've changed the structure of the tree since it seems that it really includes nodes at levels 0, 1 and 2 rather than including nodes at higher levels. Obviously, you can change this back if that's not the case.