# tikz-qtree spoils tikz trees

When I enable the tikz-qtree package, the tree I am drawing with the tikz trees library looks different. Specifically the edges are no longer pointing to proper places on the nodes. In the example below, the tree looks fine when I comment out \usepackage{tikz-qtree}

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}
[rotate=90]
\node{a}
child {
node{c}
child {
node {d}
child { node {g} child {node {h}} }
child { node {e} child {node {f}}  }
}
}
child {
node{b}
}
;
\end{tikzpicture}

\end{document}


-
I took the liberty of uploading an image illustrating the problem; I hope it's OK. –  Gonzalo Medina Aug 13 '12 at 1:00
Yes - thank you. I didn't have enough rep to post images for my first question! –  Thomas Aug 13 '12 at 15:58

The problem stems from the fact that the tikz-qtree redefines the command \tikz@edge@to@parent@path which is used to draw the edges from the parents to the children. It does this to include the specific node anchors for the parents and children (rather than them being computed automatically). To do this properly, it needs to know the direction in which the tree is growing. This is done by setting the key grow=<dir>, which is the "right" way to do it for all trees, whether qtree or not.

There may well be other things that are overwritten by the tikz-qtree package but this is the one that is causing the effect you see. Compare the following example, produced by varying the packages and so forth.

1. Original code:

2. With grow=right instead of rotate=90:

3. Loading tikz-qtree:

4. Loading tikz-qtree and grow=right:

5. Loading tikz-qtree but restoring \tikz@edge@to@parent@path (no difference for grow=right versus rotate=90):

Notice the effect of specifying the actual anchors by comparing the first and fourth examples: the lines are joined where they meet at the parent.

So, to get it looking exactly as if you hadn't loaded tikz-qtree, you need to at least restore the definition of \tikz@edge@to@parent@path (there may be other things that will come up with more complicated examples). If all you want is something that still looks right with either loading or not loading tikz-qtree then using the key grow=right might be the simplest method.

Here's the save-and-restore code.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/66884/86}

\usepackage{tikz}
\usetikzlibrary{trees}
\makeatletter
\let\orig@tikz@edge@to@parent@path=\tikz@edge@to@parent@path
\tikzset{
original tree type/.code={%
\let\tikz@edge@to@parent@path=\orig@tikz@edge@to@parent@path
}
}
\makeatother
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}
[rotate=90,original tree type]
\node{a}
child {
node{c}
child {
node {d}
child { node {g} child {node {h}} }
child { node {e} child {node {f}}  }
}
}
child {
node{b}
}
;
\end{tikzpicture}
\end{document}

-
Thank you for the response Andrew. Adding grow=right solved the problem. Just one more thing to clarify: with tikz-qtree, did you leave out the rotate=90? –  Thomas Aug 13 '12 at 16:02
@Thomas Yes. In all my tests, I never used both of grow=right and rotate=90. For a single tree (without tikz-qtree) they have a similar effect but the scope of rotate=90 is wider as it affects all coordinates in that picture. So I would prefer grow=right as the more treeish option to use. –  Loop Space Aug 13 '12 at 16:20
Interesting, because if I only specify grow=right, it actually grows downward when tikz-qtree is loaded. –  Thomas Aug 14 '12 at 17:27
@Thomas That's not the behaviour that I get. Maybe we're using different versions of TikZ and/or tikz-qtree. I'm on the versions that come with TL2012. –  Loop Space Aug 14 '12 at 19:16
Indeed, I only need both grow=right and rotate=90 using TL2010 –  Thomas Aug 15 '12 at 2:07