Take the 2-minute tour ×

I'm trying to draw a tree like this:

The root has three children and every of this two... The nodes in the first two tiers has additional informations..

I searched for examples like that, but could only find trees, which children always have the same amount of children (for example here: http://www.texample.net/tikz/examples/feature/trees/).

I thank you for your help!

enter image description here

share|improve this question

2 Answers 2

up vote 11 down vote accepted

You can use the positioning library to place nodes relative to each other. Like \node[left=<dimen/factor> of <another node>] {}. Just give the nodes inside your tree a name. To get any amount of children simply add or remove child{ ... }. For more information please take a look at the tikz manual (especially "18 Making Trees Grow" and "16.5.3 Advanced Placement Options")

Update thx for Qrrbrbirlbel noting that the baseline alignment wasn't right. So I used base left and base right as suggested.

Now it was necessary to use a coordinate like (wAB.east |- AB) to get horizontal lines (uses the x coordinate of wAB.east and the y coordiante of AB).

For an example, you can look at this tree (I tried to recreate your tree)




\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=2cm}]
\node (abc) {$ABC$} child { %node abc
    node (AB) {AB} %node AB
    child { node {$A\rightarrow BC$} }
    child { node {$B\rightarrow AC$} }
} child {
    node (AC) {AC} %node AC
    child { node {$A\rightarrow BC$} }
    child { node {$C\rightarrow AB$} }
} child  {
    node (A) {A} %node A
    child { node {$B\rightarrow AC$} }
    child { node {$C\rightarrow AB$} }

%relative to node AB
\node[base left=.5 of AB] (wAB) {\uwave{$A,b$}};
\draw (wAB.east |- AB) edge[<-] (AB);
\draw node[base right=.5 of AB] {$C$} edge[<-] (AB);
%relative to node AC
\node[base left=.5 of AC] (wAC) {\uwave{$A,C$}} ;
\draw (wAC.east |- AC) edge[<-] (AC);
\draw node[right=.5 of AC] {$B$} edge[<-] (AC);
%relative to node A
\draw node[base left=.5 of A] {$BC$} edge[<-] (A);
\node[base right=.5 of A] (wBC) {\uwave{$B,C$}};
\draw (wBC.west |- A) edge[<-] (A);
%relative to node abc
\node[base left=of abc] {$\uwave{\hspace{3ex}}=(k-1)-\mathrm{Itemsets}$} ;
\node[base right=.5 of abc] (wABACBC) {\uwave{$AB,AC,BC$}};
\draw (wABACBC.west |- abc) edge[<-] (abc);


share|improve this answer
Use base right and base left. These things might also be achieved with pins. –  Qrrbrbirlbel Dec 20 '13 at 4:53
Thank you very much! –  mrbela Dec 20 '13 at 13:18
@Qrrbrbirlbel thx for the suggestion. I didn't pay attention to the alignment of the baseline. Just enhanced my solution. –  someonr Dec 20 '13 at 15:39

This can also be done using tikz-qtree, which is a package that takes the syntax of the qtree package for writing trees and combines it with TikZ. You can have an arbitrary number of children for each root with this package and its syntax.

Similar to @someonr's solution, this solution also uses the positioning library to place the additional information in the top tier, but the additional information in the second tier is simply added as part of the roots in the second tier. You could also do this with the positioning library and syntax, if you would prefer. You would just have to declare each root in the second tier of the tree as a \node, and then you could place the additional information relative to that node.


\usepackage{amsmath} % needed for \text command in math mode

\usepackage{tikz-qtree} % needed for the tree syntax
\usetikzlibrary{positioning} % needed for placing nodes relative to one another

\usepackage[normalem]{ulem} % needed for wavy underline; the `normalem` option preserves the usual treatment of \emph as italic; without it, `ulem` causes \emph to be rendered as underlined material


        [.A$\rightarrow$BC ]
        [.B$\rightarrow$AC ]
        [.A$\rightarrow$BC ]
        [.C$\rightarrow$AB ]
        [.B$\rightarrow$AC ]
        [.C$\rightarrow$AB ]    
\node [base right = of ABC] {\uwave{AB, AC, BC}};
\node [base left = of ABC] {$=(k-1) - \text{Itemsets}$};


enter image description here

share|improve this answer

Your Answer


