# Leaf nodes in tikz-qtree are not aligned with parents when using grow=left

I am building a rotated tree using tikz-qtree. Whenever i use the setting "grow=left", the leaf nodes will be shifted a constant distance compared to their parent nodes, so that the lines between them aren't vertical. This does not seem dependent on the rotation.

Is there any way to avoid it? :)

My code is:

\documentclass[12pt, a4paper]{article}
\usepackage{tikz-qtree}

\begin{document}

\begin{figure}[ht]
\centering
\begin{tikzpicture}[grow=left, sibling distance=5pt,rotate=90,transform shape]
\tikzset{frontier/.style={distance from root=275pt}}
\Tree [
[tip1 ]
[
[tip2 ]
[
[
[tip3 ]
[
[
[tip4 ]
[
[tip5 ]
[tip6 ]
]
]
[
[
[tip7 ]
[tip8 ]
]
[
[
[tip9 ]
[tip10 ]
]
[
[tip11 ]
[tip12 ]
]
]
]
]
]
[
[tip13 ]
[
[tip14 ]
[
[
[tip15 ]
[tip16 ]
]
[
[
[tip17 ]
[tip18 ]
]
[
[tip19 ]
[tip20 ]
]
]
]
]
]
]
]
]
\end{tikzpicture}
\caption{Dendogram}
\label{fig:dendogram}
\end{figure}

\end{document}


And the resulting figure is:

• Welcome to TeX.se. Please don't post code fragments. Instead, edit your question to include the fragment in a compilable minimal document that people can play with. – Alan Munn Nov 17 '19 at 19:18

It seems that tikz-qtree aligns the base anchor of the leaf nodes with the corresponding parent node if there is only one branch. Then, it draws the branch connecting the parent node to the center anchor of the leaf node. This works for vertical trees, but causes misalignment for horizontal trees.

every leaf node/.append style={anchor=center}


to the options of your tikzpicture.

\documentclass[12pt, a4paper]{article}
\usepackage{tikz-qtree}

\begin{document}

\begin{figure}[ht]
\centering
\begin{tikzpicture}[grow=left, sibling distance=5pt, rotate=90, transform shape, every leaf node/.append style={anchor=center}]
\tikzset{frontier/.style={distance from root=275pt}}
\Tree [
[tip1 ]
[
[tip2 ]
[
[
[tip3 ]
[
[
[tip4 ]
[
[tip5 ]
[tip6 ]
]
]
[
[
[tip7 ]
[tip8 ]
]
[
[
[tip9 ]
[tip10 ]
]
[
[tip11 ]
[tip12 ]
]
]
]
]
]
[
[tip13 ]
[
[tip14 ]
[
[
[tip15 ]
[tip16 ]
]
[
[
[tip17 ]
[tip18 ]
]
[
[tip19 ]
[tip20 ]
]
]
]
]
]
]
]
]
\end{tikzpicture}
\caption{Dendogram}
\label{fig:dendogram}
\end{figure}

\end{document}


• Begs for forest, though ;). – cfr Nov 17 '19 at 23:35

hm, your dendogram can be translated to forest as:

\documentclass[12pt, a4paper]{article}
\usepackage{forest}

\begin{document}
\begin{figure}[ht]
\centering
\begin{forest}
for tree = {
s sep=0pt,
if n children=0{rotate=90,anchor=east,tier=word}%
{coordinate}
}
[
[[tip1]]
[
[[tip2]]
[
[
[[tip3]]
[
[
[[tip4]]
[
[[tip5]]
[[tip6]]
]
]
[
[
[[tip7]]
[[tip8]]
]
[
[
[[tip9]]
[[tip10]]
]
[
[[tip11]]
[[tip12]]
]
]
]
]
]
[
[[tip13]]
[
[[tip14]]
[
[
[[tip15]]
[[tip16]]
]
[
[
[[tip17]]
[[tip18]]
]
[
[[tip19]]
[[tip20]]
]
]
]
]
]
]
]
]
\end{forest}
\caption{Dendogram}
\label{fig:dendogram}
\end{figure}
\end{document}


• Are there any significant advantages of using forest over tikz-qtree? – user43228 Nov 18 '19 at 11:57
• @user43228, `forest is dedicated for drawn trees. It is very powerful, ... however in your particular case as you can see, in code between them is no big difference. I wrote answer as response to cfr comment :-) – Zarko Nov 18 '19 at 12:07