While I still wonder about (\tikzparentnode.south |- 0,-10pt -| \tikzchildnode)
, the approach in usual TikZ (and forest
) is even a little bit more comprehensible (for me at least):
edge path={\noexpand\path[\forestoption{edge}]
(\forestOve{\forestove{@parent}}{name}.parent anchor)
-- ([shift={(0,-10pt)}]
\forestOve{\forestove{@parent}}{name} -| \forestove{name})
-- (\forestove{name}.child anchor)
\forestoption{edge label};
}
The kink of the line is shifted 10pt
downwards from parent -| child
.
Code
\documentclass[tikz,convert=false]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={%
% re-establishing the defaults:
child anchor=north,
parent anchor=south,
edge path={\noexpand\path[\forestoption{edge}]
(\forestOve{\forestove{@parent}}{name}.parent anchor)
-- ([shift={(0,-10pt)}]
\forestOve{\forestove{@parent}}{name} -| \forestove{name})
-- (\forestove{name}.child anchor)
\forestoption{edge label};
}
}
[ZZ
[Bax
[X
[Y [A ] [B ] ]
[Z [C ] [D ] ] ]
[F
[M [E ] [F ] ]
[G [G ] [H ] ] ] ]
[A
[B
[S [I [P][R][T][V][U]] [J ] ]
[I [K ] [L ] ] ]
[M
[L [M ] [N ] ]
[A [O ] [P ] ] ] ] ] ]
\end{forest}
\end{document}
Output
You are loading the edges
library but not actually using it, which is odd since this is precisely the kind of style it supports. Moreover, it does away with the need to fake the structure of the tree, allowing you to keep the intuitive parent-child relationships in your mark-up.
In this case, the folder
style is the obvious choice, at least ignoring its misleading name. The only issue really is that it doesn't do the right thing when it applies only beyond a certain level and, because it tries to do the right thing in a clever way, you have to override it late in the processing of the tree.
For example,
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{
parent/.style={align=center,text width=4cm,fill=gray!50,rounded corners=2pt},
child/.style={align=center,text width=2.5cm,fill=gray!20,rounded corners=6pt},
grandchild/.style={fill=white,text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
thick,
drop shadow,
node options={
draw,
font=\sffamily
},
edge={
semithick,
-Latex
},
where level=0{
parent,
l sep'=0.8cm,
s sep'=1.0cm,
}{
folder,
grow'=0,
},
where level=1{
minimum height=1cm,
child,
l sep=7.5mm,
for descendants={%
grandchild,
minimum height=0.6cm,
},
for children={
before computing xy={s+=5mm},
}
}{},
}
[\large Long text with line break%
[\textbf{Test 1} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 2} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 3} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 4} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
]
\end{forest}
\end{document}
Best Answer
Your answer will work but is needlessly verbose as you can simply use relative node names to specify the
edge path
.(!u)
refers to the parent of the current node.()
refers to the current node.You can also align the terminal nodes for the whole tree in the preamble:
but anchoring the nodes at the left side makes for a neater tree:
The result:
Complete code: