如何绘制如下所示的 B 树

如何绘制如下所示的 B 树

我正在尝试绘制一棵与叶子有垂直连接的 B 树;而且,节点内的值仅由空格分隔。

参见下图。

B-树

到目前为止,我已经关注。

\documentclass[titlepage,11pt,a4paper]{article}

\usepackage{tikz} %draw trees etc
\usetikzlibrary{shapes.multipart, shapes.misc, calc}
%\usepackage{tikz-qtree}


\begin{document}

\tikzstyle{bplus}=[rectangle split, rectangle split horizontal, rectangle split ignore empty parts, rounded corners, inner sep=7pt, draw, fill=white]

\begin{tikzpicture}
\tikzstyle{every node}=[bplus]
\tikzstyle{level 1}=[sibling distance=10mm]
%\tikzstyle{level 2}=[sibling distance=20mm]

    \node {19 \nodepart{two} 21}
        child {node{ o }}
        child {node{ o }}
        child {node{ o }}
        ;
\end{tikzpicture}

\end{document}

有3点我无法理解。

  1. 如何删除垂直线分隔符?
  2. 如何将空节点生成一个圆圈?
  3. 如何使连接垂直?

答案1

没有trees

\documentclass[titlepage,11pt,a4paper]{article}

\usepackage{tikz} %draw trees etc
\usetikzlibrary{fit, matrix, positioning, calc}
%\usepackage{tikz-qtree}

\tikzset{
    bplus/.style={rounded corners, inner sep=7pt, draw, fill=white}
}   

\begin{document}


\begin{tikzpicture}
    \matrix[matrix of nodes, nodes in empty cells, nodes={draw, circle, minimum size=5mm}, column sep=2mm,] (a)
    {&&&[5mm]&&[5mm]&&\\};
    \node[fit=(a-1-1) (a-1-3), rounded corners, draw, above=1cm of a-1-2, label={[font=\bfseries]center:{1\ \ 3}}] (b1) {};
    \node[fit=(a-1-6) (a-1-8), rounded corners, draw, above=1cm of a-1-7, label={[font=\bfseries]center:{12\ \ 15}}] (b3) {};
    \path (b1)--(b3) node[midway, fit=(a-1-4) (a-1-5), rounded corners, draw, label={[font=\bfseries]center:{6}}] (b2) {};
    \node[fit=(a-1-6) (a-1-8), rounded corners, draw, above=1cm of b2, label={[font=\bfseries]center:{5\ \ 7}}] (c1) {};
    \foreach \i in {1,...,3}{
        \draw (a-1-\i)--(a-1-\i|-b1.south);
        \draw (b\i)--(c1);}
    \foreach \i in {4,...,5}
        \draw (a-1-\i)--(a-1-\i|-b2.south);
    \foreach \i in {6,...,8}
        \draw (a-1-\i)--(a-1-\i|-b3.south);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容