# Horizontal hierarchy tree in tikz-qtree: bad layout for longer node-names

I'm trying to set a number of hierarchy trees directly in LaTeX and found tikz-qtree quite helpful for this task.

Since the descriptions for the nodes and children are rather long words, the layout doesn't seem optimal in a vertical tree.

Additionally, I'll merge those trees in a bigger tree and then things start getting crowded.

So, I thought of a horizontal tree. They're nice, too. But I just cannot get them to work properly.

The tikz-qtree-manual is pretty short and the containing example-nodes consist of a small number of letters only.

What I'm trying to achieve is something like the first tree, but "rotated" by 90°. The titles of nodes and children will be long (sometimes several words) and it will be a total of three levels in the end.

Simply growing the first tree to the right does not suffice. :) Where can I find documentation about the properties of the "edge from parent path"-parameter? I didn't find them in the tikz-manual either.

I looked into the regular tikz-package, too, but ran into similar issues there. tikz-qtree has a prettier syntax, so I stuck with it.. Maybe something like dirtree would be suited better?

Anyway, here's a minimal working example:

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}

\begin{document}

Nice vertical tree. Bad for lots of subcategories.
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tikzset{edge from parent/.style=
{thick, draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\Tree
[. parent
[. {nice child0} ]
[. child1 ]
[. child2 ]
[. child3 ]
]
\end{tikzpicture}
\end{figure}

Vertical tree with different growth direction. Doesn't look quite right. o\_O
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tikzset{grow'=right, edge from parent/.style=
{thick, draw,
edge from parent path={(\tikzparentnode.east)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\tikzset{every tree node/.style={anchor=base west}}
\Tree
[. parent
[. {nice child0} ]
[. child1 ]
[. child2 ]
[. child3 ]
]
\end{tikzpicture}
\end{figure}

Nice horizontal tree. Good for lots of subcategories, but wrong' edges.
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tikzset{grow'=right,level distance=32pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree
[.p
[.c0 ]
[.c1 ]
[.c2 ]
[.c3 ]
]
\end{tikzpicture}
\end{figure}

Almost identical horizontal tree as above, but messed up layout for longer node-names.
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tikzset{grow'=right,level distance=32pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree
[.parent
[.c1 ]
[.c2 ]
]
\end{tikzpicture}
\end{figure}

\end{document}


Thank you guys for any pointers and your help!

-
Okay, I played around with dirtree now. It makes things look pretty, but it really is not suited for several categories next to each other. Additionally, it does not allow the drawing of borders around nodes. Hm, tikz looks so close, but I cannot get it to work. The TikZ-manual is a bit cryptic about the usage of the edges from nodes, too. –  dhst Jan 18 '12 at 19:29
There's a couple of solutions here Drawing a directory listing a la the tree command in TikZ that might be helpful. –  Alan Munn Jan 18 '12 at 21:48
I saw this solution, but it's not really what I'm looking for. Besides, dirtree makes exactly those trees, but a whole lot easier (and prettier). I'll make a quick mock-up tomorrow to make things a bit more clear. Thank you for your reply, Alan! –  dhst Jan 19 '12 at 0:33
It took a while, but I fired up Visio 2010 yesterday and clicked together a vertical Org-Chart that has a good layout. That said, it was pain to to this in Visio and the .pdf-output messes things up quite a bit. Anyway, here it goes: i.imgur.com/NdK0t.png Visio however is not capable of making those org-chart vertically in a nice fashion, so I used OmniGraffle for this. It looks like this: i.imgur.com/wEcpe.png Any treexperts out there? Thank you! –  dhst Jan 25 '12 at 17:50

Here's a solution using tikz-qtree plus the TikZ trees library, which offers a pre-made edge from parent fork right path for such trees.

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}

\begin{tikzpicture}[grow'=right,level distance=1.25in,sibling distance=.25in]
\tikzset{edge from parent/.style=
{thick, draw, edge from parent fork right},
every tree node/.style=
{draw,minimum width=1in,text width=1in,align=center}}
\Tree
[. parent
[.{nice child0}
[.{grandchild0-0 } ]
[.{grandchild0-1 } ]
[.{grandchild0-2 } ]
[.{grandchild0-3 } ]
]
[.child1
[.{grandchild1-0 } ]
[.{grandchild1-1 } ]
[.{grandchild1-2 } ]
]
[.child2 ]
[.child3 ]
]
\end{tikzpicture}
\end{document}
`

-