I know how to create a multipart node in TikZ using \nodepart
, and I know how I can draw lines from these nodeparts to hook them up to other nodes:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
bnode/.style = {
draw,
rectangle split,
rectangle split horizontal,
rectangle split parts=4
}
}
\begin{document}
\begin{tikzpicture}
\node[bnode]
(root)
{ \nodepart{one}
$12$ \nodepart{two}
$15$ \nodepart{three}
$20$ \nodepart{four}
$\times$};
\draw[->]
(root.south west) -- +(-4,-1)
node[bnode, anchor=north]
(childnode)
{ \nodepart{one}
$3$ \nodepart{two}
$9$ \nodepart{three}
$10$ \nodepart{four}
$12$};
\draw[->]
(root.one split south) -- +(-2,-1)
node[bnode, anchor=north]
(childnode)
{ \nodepart{one}
$13$ \nodepart{two}
$14$ \nodepart{three}
$15$ \nodepart{four}
$\times$};
\draw[->]
(root.two split south) -- +(0,-1)
node[bnode, anchor=north]
(childnode)
{ \nodepart{one}
$17$ \nodepart{two}
$18$ \nodepart{three}
$\times$ \nodepart{four}
$\times$};
\draw[->]
(root.three split south) -- +(2,-1)
node[bnode, anchor=north]
(childnode)
{ \nodepart{one}
$21$ \nodepart{two}
$29$ \nodepart{three}
$\times$ \nodepart{four}
$\times$};
\end{tikzpicture}
\end{document}
Renders:
Even in this simple example I had to calculate the correct location of the child nodes because they are overlapping. Imagine adding another level to the tree. These calculations would become very tedious.
I know TikZ has some nice tree syntax to easily draw trees, but I don't immediatly see how it applies here.
Is there a way to use TikZ' child
syntax to work with multipart nodes so that I don't have to worry about the spacing and location of their child nodes.
To clarify: every part of a multipart node should be able to have it's own child proper, and the children are multipart nodes themselves, which again can have multiple children (one for each nodepart).