I think this would be a good question how to bring a customized flowchart (your own) in MS Word to LaTeX. Well, I have attached a World file, and I am trying to convert that in LaTex. The Save as "type" LaTeX did not work, and generated a nonsense PDF. So, what would be the best way?
I do not know how to attach a word file here. so I have put a snapshot of that.
One way is to re-type this in LaTeX, but I do not feel confidence to do that (feel difficulty to have this arrows)
Clearly, when I bring this as figure into LaTeX source file, the fonts are not match with other stuff in paper. Therefore, I want to convert that (as simplest way perhaps)
Best Answer
Alan's answer works OK, but with the current version of Forest there is no need to define the
edge path
from scratch. Instead, we can use theedges
library with the optionforked edges
. Moreover, we can eliminategrowth parent anchor=east
as it doesn't do anything (even in the old version of Forest), and we can use theparent
andchildren
anchors rather thaneast
andwest
to make the code more flexible.In fact,
grow=east
is enough on its own, so we can dropparent anchor
andchild anchor
specifications altogether.This gives us the following code for the same output as Alan showed in his answer.
On closer inspection, however, the lines could be better:
The default definition of
forked edges
isSo, let's try redefining it so that the
forked edge
is only used if a node has more than one child by adding this redefinition:This is better:
However, the arrow is still angled - it is not quite horizontal. What we need to do is define an alternative
edge path
for the case where there is precisely one child.The default edge is drawn from the parent node's parent anchor
(!u.parent anchor)
to the child node's child anchor(.child anchor)
. We'd like the start of the arrow to be horizontally aligned with(.child anchor)
. (We could instead align the end point with the parent's parent anchor, of course.)This produces the horizontal arrow we're looking for:
However, this may not be the best solution. If the parent and child nodes are too different in size, we might get a strange alignment. So perhaps we should instead tell Forest to align the child with the parent so that the child's child anchor lines up with the parent's parent anchor.
does the trick.
Right now, the result looks like this:
This is better, but it would be nice if we could align the middle child with the parent when the parent has an odd number of children. For example, if
D
's edge was aligned with the line drawn from the root node.This is a little trickier, but not much so. We can use the
calign=child edge
trick again and set the middle child to be its parent's 'primary' child.We can add this into the preamble at the beginning of our
forest
environment:In fact, since any node with exactly 1 child has an odd number of children, we can also drop the redefinition of
forked edges
since we'll get a straight arrow now anyway:Stealing Greek code shamelessly from Marco:
EDIT
Your code produces 'gaps' because
[[<something>]]
produces an empty node and then a node with[<something>]
. To eliminate the empty node, just say[<something>]
.Note that with version 1, you do need to specify the
parent anchor=east, child anchor=west
and to change theedge path
. There is noforked edges
. Also, it is not easy to eliminate the kink when there is only one child becausecalign=child edge
is buggy in versions prior to 2.01. You could still do it, but it would be much easier to update than to work around the bug. This isn't an issue if your tree has no only children, but if you have other trees, it might be. Nor is it easy to align the edges for similar reasons. You would need to do something withedge path
to get it working.With the current package, on the other hand, your tree can easily be adjusted to look like this and the code is simpler, too: