Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to draw a tree with the root node at the bottom? The image below demonstrates what I'd like, but is upside down.

Tree diagram

I've looked into similar questions, most notably

How do I draw a B+ tree in latex?

But they haven't been entirely helpful.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You can use the grow key, described on page 218 of the pgfmanual:

This key is used to define the direction in which the tree will grow. The direction can either be an angle in degrees or one of the following special text strings: down, up, left, right, north, south, east, west, north east, north west, south east, and south west. All of these have “their obvious meaning,” so, say, south west is the same as the angle -135◦.

In your case, you can use grow=up; a little example:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
[level distance=10mm,
every node/.style={fill=red!60,circle,inner sep=1pt},
level 1/.style={sibling distance=20mm,nodes={fill=red!45}},
level 2/.style={sibling distance=10mm,nodes={fill=red!30}},
level 3/.style={sibling distance=5mm,nodes={fill=red!25}}]
\node  {31} [grow=up]
child {node {30}
child {node {20}
child {node {5}}
child {node {4}}
}
child {node {10}
child {node {9}}
child {node {1}}
}
}
child {node {20}
child {node {19}
child {node {1}}
child[missing]
}
child {node {18}}
};
\end{tikzpicture}

\end{document}

enter image description here

Depending on the desired order for the nodes, you could use grow' instead:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
[level distance=10mm,
every node/.style={fill=red!60,circle,inner sep=1pt},
level 1/.style={sibling distance=20mm,nodes={fill=red!45}},
level 2/.style={sibling distance=10mm,nodes={fill=red!30}},
level 3/.style={sibling distance=5mm,nodes={fill=red!25}}]
\node  {31} [grow'=up]
child {node {30}
child {node {20}
child {node {5}}
child {node {4}}
}
child {node {10}
child {node {9}}
child {node {1}}
}
}
child {node {20}
child {node {19}
child {node {1}}
child[missing]
}
child {node {18}}
};
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Awesome, cheers :) I knew it would be something straight forward –  jackweirdy Oct 6 '12 at 19:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.