2

In my answer to question improving-tree-diagram i wrongly use forked edges:

\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}

\begin{document}
    \begin{forest}
    for tree={
      font=\footnotesize,
      draw, semithick, rounded corners,
            align = center,
        inner sep = 3mm,
             edge = {draw, semithick, -stealth},
             grow = east,
    forked edges, % <-- wrong, it should not be inside scope of "for tree"
            l sep = 12mm% level distance
                }
    [Multimedia\\ RSs
      [Multimedia\\ Content]
      [Multimedia\\ Content]
    ]
  \end{forest}
\end{document}

which gives:

enter image description here

However, with correct forked edge instead of forked edges the result is unacceptable:

enter image description here

It is corrected to first one, if I added to for tree options:

parent anchor = east, child anchor = west,

or if I use forked edges outside of tree, for example:

  ...
 \begin{forest}
     forked edges,
   for tree={
      font=\footnotesize,
      draw, semithick, rounded corners,
            align = center,
        inner sep = 3mm,
             edge = {draw, semithick, -stealth},
             grow = east,
            l sep = 12mm% level distance
                }
 ...

I wonder, why the forked edge and forked edges gives different result?

One more question: why the point of the branch of edges is not on the middle of level distance if it is defined, for example l sep=12mm regardless if parents/child anchors are defined?

I read forest documentation, but didn't find anything usable about mentioned (maybe I need read it again and again ... and also look into code) .

  • I answered your first question in a comment correcting my earlier mistake. – cfr Oct 11 '16 at 1:34
  • Yeas, you do (i didn't see your comment during writing my question). Anyway, I found that this issue is poorly addressed in package documentation, so any additional explanation with special attention to forked edges growing in horizontal direction would be very welcome. Also the issue how to set branching point on middle of level distance is very actual (at least for me). – Zarko Oct 11 '16 at 1:44
  • It is really a TikZ question - the first one, I mean. The second I suspect I haven't understood as I don't understand why you'd expect l sep to influence folder sep. Probably I've missed something - very tired! – cfr Oct 11 '16 at 2:26
5

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:

anchor variations

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.

further variations on a theme

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.

deeper sep

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}
  • Thank you for exhaustive answer. Some features of forest is now more clear to me. Regarding second question: to my opinion the distance, where edges branch away should be default set to half of level distance and no to 1 em, and if one desire to have different position of this point, she/he can determine it by fork sep. Well, this is actually feature request :-). – Zarko Oct 12 '16 at 18:03
  • But what you call the level distance is no such thing. It is the minimum separation between parent and children. Nodes on a level need not be aligned in the tree. And some children may be a far greater distance from their parent than others. If child 1 and child 2 are different distances from their parent, where should the path branch exactly? But anyway, it is no good directing feature requests to me, as you are well aware! – cfr Oct 12 '16 at 22:19
  • I'm very sorry for using wrong vocabulary. I still "live" in TikZ tree world. About feature request: I wish only to say, how I like to be determined the point of edges branch away and that is actually feature request (which of course can be only addressed to package author). How to determine position of this point: as you explained, I see now that it is not so simple as I imagine in the first place. – Zarko Oct 13 '16 at 20:18
  • @Zarko Don't apologise. I was just explaining that l sep doesn't mean (or do!) what you seemed to think. You should ask Sašo in the Forest chat room about the feature request. – cfr Oct 13 '16 at 21:47
  • I will once, but first I like to become more familiar with it. This for sure will not be very soon :-) – Zarko Oct 13 '16 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.