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)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{positioning}
\usepackage[normalem]{ulem}
\begin{document}
\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);
\end{tikzpicture}
\end{document}
