You can use two trees sitting on top of each other.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=2.5cm]
\node (topnode) at (0,5) { {\{\{1\}\{2\}\}\{3\}\{4\}}\} }
child { node {{\{\{1,2\}\{3\}\{4\}}\}} }
child { node {{\{\{1,3\}\{2\}\{4\}}\}} }
child { node {{\{\{1,4\}\{2\}\{3\}}\}} }
child { node {{\{\{2,3\}\{1\}\{4\}}\}} }
child { node {{\{\{2,4\}\{1\}\{3\}}\}} }
child { node {{\{\{3,4\}\{1\}\{2\}}\}} }
;
\node[minimum width=3cm](bottomnode) {\{\{1,2,3,4\}\}} [grow'=up]
child { node {{\{\{1,2,3\}\{4\}}\}} }
child { node {{\{\{1,2,4\}\{3\}}\}} }
child { node {{\{\{1,2\}\{3,4\}}\}} }
child { node {{\{\{1,3,4\}\{2\}}\}} }
child { node {{\{\{1,3\}\{2,4\}}\}} }
child { node {{\{\{1,4\}\{2,3\}}\}} }
child { node {{\{\{2,3,4\}\{1\}}\}} }
;
\foreach \x in {1,2,3}{
\draw (topnode-1) -- (bottomnode-\x);
}
\end{tikzpicture}
\end{document}
I'll leave the connection lines to you if you don't mind. You can access each node by first writing up the parent node name followed by a dash and the item number e.g. (topnode-5)
.
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}
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}
Best Answer
You can use missing children (Section 18.5.3 Missing Children in the pgf manual):