I want to align some trees I am creating. I want the root node of all the trees to be on the same line. Currently for each tree I create, the root node of each subsequent tree is on a line after the bottom of the previous tree. How can I do this?
Asked
Active
Viewed 743 times
1 Answers
2
In a very simple manner, you can specify the position of the root in the picture. Look at this MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[edge from parent fork down,
every node/.style={fill=red!30,rounded corners},
edge from parent/.style={red,thick,draw}]
\node at (0,0) {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\node at (4,0) {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\node at (8,0) {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\end{tikzpicture}
\end{document}
This will be graphically:

Claudio Fiandrino
- 63,575
tikzpicture. You can also refer to the pgfmanual page 114 (version October 25, 2010). – Claudio Fiandrino Apr 07 '12 at 14:22[ every node/.style={red!80, rounded corners,draw}, edge from parent/.style={red!80,thick,draw}]– Claudio Fiandrino Apr 07 '12 at 14:28[missing]key on a child node. See How do I make an unbalanced binary tree. You may also want to check outtikz-qtree(see my answer there) if you are drawing trees a lot; its syntax is much more compact. – Alan Munn Apr 07 '12 at 14:46