[Tex/LaTex] Square edges in forest package

foresttikz-pgftikz-qtreetrees

I can easily do trees with horizontal (square) edges in tikz-qtree (see MWE). The forest package is however a far superior alternative for my purposes. However, every attempt to do either horizontal or vertical trees with square edges in forest is either ignored, or leads to compilation failure (for example inserting the \tikzset line into the forest tree). Is this possible?

A helping hand would be very much appreciated here.

 \documentclass[10pt,twoside,a4paper]{memoir}
 \usepackage{graphicx}
 \usepackage{forest}
 \usepackage{tikz-qtree}

 \begin{document}

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


 \begin{forest}
 [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}

MWE Output

Best Answer

You need to do \begin{forest} for tree={edge path=<your path>}} (without []!).

I adjusted the distance a little bit, better would be to use for example half the level distance and not a fixed distance.

One can also use my paths.ortho library (needs both tikzlibarypaths.ortho.code.tex and tikzlibarypaths.ortho.tex) and be available to use |-| instead of --.

Code

\documentclass[10pt,twoside,a4paper]{memoir}
\usepackage{graphicx}
\usepackage{forest}
\usepackage{tikz-qtree}
\begin{document}

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


\begin{forest} for tree={
    edge path={\noexpand\path[\forestoption{edge}] (\forestOve{\forestove{@parent}}{name}.parent anchor) -- +(0,-12pt)-| (\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