Here are the definitions for forked edge
and forked edges
from forest-lib-edges.sty
.
\forestset{
declare dimen={fork sep}{0.5em},
forked edge/.style={
edge={rotate/.pgfmath=grow()},
edge path'={(!u.parent anchor) -- ++(\forestoption{fork sep},0) |- (.child anchor)},
},
forked edges/.style={
for tree={parent anchor=children},
for descendants={child anchor=parent,forked edge}
},
}
So we see that forked edges
not only applies forked edge
to all descendants, but adjusts the parent anchor
for the tree and the child anchor
for the descendants as well.
I don't think that forked edge
is correct here. It is true that you don't want forked edges
because then you'll have
for tree={
for tree={
...
which can cause problems.
However, if you use \forked edge
without setting the parent/child anchors, then Forest defaults to using the (<node>)
itself and TikZ then selects a border anchor in its usual way. However, the initial part of the forked path is drawn relative to the starting point. The starting point is also (<node>)
but this time TikZ is measuring relative to rather than tracing a path from. So rather than using the node's border anchor, it uses the node's default anchor, which is .center
by default.
So although the path starts from the appropriate border anchor, its initial segment takes it towards a location measured relative to the .center
anchor and not measured relative to the border anchor.
Here's a visualisation:
The path starts from (a.east)
, which is right, but the point ++(.5em,0)
from (a)
is measured from (a.center)
. This is shown in red. The first part of the path, therefore, is the part shown in blue which is not .5em
, of course. The remainder of the path is then in green.
We can see the same thing in the default growth direction where the edge takes rotate=-90
.
I don't understand your second question. Why should l sep
affect the branching point? I think you are asking why you don't get something like the following.
This can be done by adjusting fork sep
.
\begin{forest}
forked edges,
for tree={
font=\footnotesize,
draw,
semithick,
rounded corners,
align = center,
inner sep = 3mm,
edge = {semithick, -stealth},
grow = east,
l sep = 12mm,
fork sep=6mm,
}
[Multimedia\\ RSs
[Multimedia\\ Content]
[Multimedia\\ Content]
]
\end{forest}
But note also, that l sep
is a minimum distance between the closest border point of the parent and the closest border point of each child. That distance may end up being larger than the specified dimension. Forest just stops it being any smaller. (Unless it is altered later, of course, either for the whole tree or more locally.)
So you can't guarantee the midpoint in this way. To do that, you would need to alter fork sep
later, as the tree is packed because you'd need, I think, to change it for each level before the sub-trees of the nodes on that level are packed. (Or you'd have to repack afterwards.) I'm not certain of this, however - it might be sufficient to do it after the entire tree is packed, at least in many cases. (Of course, you'd want to do it before the x and y values are computed.)
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{tikzpicture}
\node [draw] (a) at (0,0) {a};
\node [draw] (b) at (1,.25) {b};
\node [draw] (c) at (1,-.25) {c};
\foreach \i in {b,c}
{
\draw [rotate=0] (a) -- ++(.5em,0) |- (\i);
\draw [rotate=0, green] (a) ++(.5em,0) |- (\i);
\draw [rotate=0, blue] (a) -- ++(.5em,0);
}
\draw [red] (a.center) -- ++(.5em,0);
\end{tikzpicture}
\begin{tikzpicture}
\node [draw] (a) at (0,0) {a};
\node [draw] (b) at (-.25,-1) {b};
\node [draw] (c) at (.25,-1) {c};
\foreach \i in {b,c}
{
\draw [rotate=-90] (a) -- ++(.5em,0) |- (\i);
\draw [rotate=-90, green] (a) ++(.5em,0) |- (\i);
\draw [rotate=-90, blue] (a) -- ++(.5em,0);
}
\draw [rotate=-90, red] (a.center) -- ++(.5em,0);
\end{tikzpicture}
\begin{forest}
forked edges,
for tree={
font=\footnotesize,
draw,
semithick,
rounded corners,
align = center,
inner sep = 3mm,
edge = {semithick, -stealth},
grow = east,
l sep = 12mm,
fork sep=6mm,
}
[Multimedia\\ RSs
[Multimedia\\ Content]
[Multimedia\\ Content]
]
\end{forest}
\end{document}
Best Answer
Not only have several people provided code for this diagram before, I've definitely answered it using Forest before.
It would be much easier if the image in the question was linked to the source since that might well give me a clue.
I know I've given a Forest solution because I found one, but I seem to have not given a link to my answer. And I remember being annoyed because I drew the diagram from scratch when the OP could have linked to code I could have copy-pasted and adapted, since it had been answered before (but maybe the code no longer worked or didn't use Forest or something).
This diagram is intensely annoying as this KEEPS happening to me.
Anyway, I updated the code I've got for Forest v.2 using a modified version of the code in my answer linked in Torbjørn T.'s comment. This version uses the
folder
style from theedges
library.