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.

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?

share|improve this question
add comment

1 Answer

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:

enter image description here

share|improve this answer
    
that's exactly what I want to do. –  Harold Rosenberger Apr 7 '12 at 14:02
    
[edge from parent fork down,every node/.style=fill=red!30,rounded corners}, edge from parent/.style={red,thick,draw}] –  Harold Rosenberger Apr 7 '12 at 14:04
    
Now, I do now have nice straight lines as shown. ALso, how can I get it to look more like a typical binary tree? Also, the top two level of my trees, the nodes are black. –  Harold Rosenberger Apr 7 '12 at 14:16
    
Happy that it works also to you. To have the picture more similar to a binary tree you just need to remove the general options in [ ] after the opening of the tikzpicture. You can also refer to the pgfmanual page 114 (version October 25, 2010). –  Claudio Fiandrino Apr 7 '12 at 14:22
1  
@HaroldRosenberger: Please clean up by removing the comments after this discussion. Comments are only for adding some valuable remark to an answer. Feel free to edit your question for adding information, or to post your own answer, or if it's derived from Claudio's solution, make an edit suggestion regarding his answer to extend it. But please delete those many comments, otherwise a mod may do it and you might keep some code though. –  Stefan Kottwitz Apr 8 '12 at 9:12
show 12 more comments

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.