[Tex/LaTex] Customized edge in forest tree

foresttikz-pgftikz-qtreetrees

Following the examples in the documentation, it is not too difficult to customize the edge of trees using the tikz-qtree package. The following code illustrates it:

\documentclass{standalone}
\usepackage{tikz-qtree}

\begin{document}

\begin{tikzpicture}
  \tikzset{
    edge from parent/.style={
      draw,
      edge from parent path={
        (\tikzparentnode.south) -- (\tikzparentnode.south |- 0,-10pt -| \tikzchildnode) -- (\tikzchildnode)
      }
    }
  }
  \Tree [.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{tikzpicture}

\end{document}

Its output is:

output of the example document

How can the same style of edges used in this example be accomplished with the forest package?

Best Answer

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

enter image description here

Related Question