# How to align a vertical tree to the upper-left corner?

How do I align vertical trees to to the top?

This is my current tree:       I want to get this tree:

^ That's a part of my current tree

I'm trying to create a graph which illustrates a path algorithm of O(N!). For readability, I only show descendants for the top node, all of the lower nodes should be postfixed by a fork- / rake-like object.

I'd appreciate an answer which shows the correct solution, plus an explanation of the used code.

My relevant code:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}
\begin{tikzpicture}
\tikzset{grow'=right,level distance=50pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={align=left,anchor=base west}}
\Tree [.\node(root){E};
[.A \node(x){R};
[.D ]
[.U ]
[.T ]
]
[.R ]
[.D ]
[.U ]
[.T ]
]
[.R ]
[.D ]
[.U ]
[.T ]
]
\draw[->](x)..controls +(north west:1.5) .. (root);
\end{tikzpicture}
\end{document}

-
I get centered dots after R if I write [ .R{\,$\cdots$} ] in the descendents of E. –  egreg Jan 13 '12 at 11:32

Perhaps a tree is not the right way to go for what you want to achieve. This example uses a matrix to place the nodes in the desired way.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[>=stealth]
\matrix[matrix of nodes,column sep=2em,row sep=1em] (tree) {
E & A & R & D & U & T \\
& R & D & U & T &   \\
& D & U & T &   &   \\
& U & T &   &   &   \\
& T &   &   &   &   \\
};
\foreach \n in {1,2,3,4,5} {\path (tree-1-1) edge (tree-\n-2);};
\foreach \n in {1,2,3,4} {\path (tree-1-2) edge (tree-\n-3);};
\foreach \n in {1,2,3} {\path (tree-1-3) edge (tree-\n-4);};
\foreach \n in {1,2} {\path (tree-1-4) edge (tree-\n-5);};
\path (tree-1-5) edge (tree-1-6);
\path (tree-1-6) edge[->,bend right=15] (tree-1-1);
\end{tikzpicture}
\end{document}


The syntax is not as comfortable as typing a tree, but the result is what you want.

-
Thanks for the answer. How can I add a fork after the other letters (looks like a <-, with the hyphen slightly shifted to the left)? –  Rob W Jan 13 '12 at 12:50
You could construct the fork with \newcommand*\myfork{\ensuremath{{-\mkern-20mu <}}} and then add that to the relevant nodes. To keep the alignment, set text width=1em in the \matrix options. –  Alan Munn Jan 14 '12 at 17:54
I ended up using the fork as suggested by @AlanMunn. Instead of manually typing it all over again, I used two RegExes to pad the & and add the \fork`. Thanks for your help! –  Rob W Jan 15 '12 at 14:39