Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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