[Tex/LaTex] TikZ: Draw a B+ Tree

tikz-pgftrees

Having consulted How do I draw a B+ tree with tikz in latex with more than 4 Key value pair in a node and How do I draw a B+ tree in latex? threads, I think the multipart feature of TikZ might just do what I need (see picture below). Is there any way to hide the vertical lines between node parts and still be able to access the multipart anchors (possibly even draw those circles)?

enter image description here

Best Answer

I tinkered a little with your problem and came up with a non-automatic version. The fact that the nodes are named with words ( one ) instead of numbers ( 1 ) didn't help my attepts to automate it ;)

If you have a splitnode called myname, then you need to call \drawdots with the two parameters node name and split count.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{xifthen}

\pgfmathsetmacro{\dotradius}{0.05}

\newcommand{\drawdots}[2]{% node, recparts
    \foreach \x/\n in {1/{one }, 2/{two }, 3/{three }, 4/{four }, 5/{five }, 6/{six }, 7/{seven }, 8/{eight }, 9/{nine }, 10/{ten }, 11/{eleven }, 12/{twelve }, 13/{thirteen }, 14/{fourteen }, 15/{fifteen }, 16/{sixteen }, 17/{seventeen }, 18/{eighteen }, 19/{nineteen }} 
    {\ifthenelse{#2>\x}{\fill (#1.\n split) circle (\dotradius);}{}}
}

\begin{document}

\begin{tikzpicture}
[   recspl/.style={rectangle split, rectangle split parts=#1, rectangle split horizontal, draw, anchor=center, rectangle split draw splits=false},
    conn/.style={out=270,in=90}]

\node[recspl=12] (a) at (0,0)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
    \nodepart{four} 4
    \nodepart{five} 5
    \nodepart{six} 6
    \nodepart{seven} 7
    \nodepart{eight} 8
    \nodepart{nine} 9
    \nodepart{ten} 10
    \nodepart{eleven} 11
    \nodepart{twelve} 12
};
\drawdots{a}{12}

\node[recspl=3] (b1) at (-5,-2)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
};
\drawdots{b1}{3}

\node[recspl=3] (b2) at (-1,-2)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
};
\drawdots{b2}{3}

\node[recspl=3] (b3) at (2,-2)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
};
\drawdots{b3}{3}

\node[recspl=3] (b4) at (6,-2)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
};
\drawdots{b4}{3}

\node[recspl=20] (c) at (0,-4)
{   1
    \nodepart{two} 2
    \nodepart{three} 3
    \nodepart{four} 4
    \nodepart{five} 5
    \nodepart{six} 6
    \nodepart{seven} 7
    \nodepart{eight} 8
    \nodepart{nine} 9
    \nodepart{ten} 10
    \nodepart{eleven} 11
    \nodepart{twelve} 12
    \nodepart{thirteen} 13
    \nodepart{fourteen} 14
    \nodepart{fifteen} 15
    \nodepart{sixteen} 16
    \nodepart{seventeen} 17
    \nodepart{eighteen} 18
    \nodepart{nineteen} 19
    \nodepart{twenty} 20
};
\drawdots{c}{20}

\draw[conn] (a.one split) to (b1.one north);
\draw[conn] (a.four split) to (b2.two north);
\draw[conn] (a.six split) to (b3.two north);
\draw[conn] (a.ten split) to (b4.one north);

\draw[conn] (b1.one split) to (c.two north);
\draw[conn] (b2.one split) to (c.seven north);
\draw[conn] (b3.two split) to (c.nine north);
\draw[conn] (b4.one split) to (c.seventeen north);
\end{tikzpicture}

\end{document}

enter image description here