5

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: enter image description here

1
  • 1
    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
    Commented Nov 17, 2019 at 19:18

2 Answers 2

5

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.

To solve this, add

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}

enter image description here

1
  • Begs for forest, though ;).
    – cfr
    Commented Nov 17, 2019 at 23:35
4

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}

enter image description here

2
  • Are there any significant advantages of using forest over tikz-qtree?
    – user43228
    Commented Nov 18, 2019 at 11:57
  • 1
    @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
    Commented Nov 18, 2019 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .