我想使用 tikzpicture 在 LaTeX 中绘制 m 路搜索树/B 树

我想使用 tikzpicture 在 LaTeX 中绘制 m 路搜索树/B 树

我想使用 tikzpicture 在 LaTeX 中绘制 m 路搜索树/B 树在此处输入图片描述

答案1

图表的前两行

\documentclass[tikz,margin=1mm]{standalone}
\usetikzlibrary{matrix}
\tikzset{
    every matrix/.style={
        inner sep=-\pgflinewidth,
        matrix of math nodes,
        column sep=-\pgflinewidth,
        nodes={
            draw=red,
            font=\color{blue},
            minimum size=.75cm,
            anchor=center
        }
    }
}
\begin{document}
\begin{tikzpicture}
\matrix[above] (t1) at (0,0) {18 & 44 & 76 & 198\\};
\matrix[below] (b1) at (0,0) {\bullet & \times & \times & \bullet & \bullet\\};
\matrix[above] (t21) at (-5,-4) {7 & 12\\};
\matrix[below] (b21) at (-5,-4) {\times & \bullet & \times\\};
\matrix[above] (t22) at (0,-4) {80 & 92 & 141\\};
\matrix[below] (b22) at (0,-4) {\bullet & \times & \times & \bullet\\};
\matrix[above] (t23) at (5,-4) {262\\};
\matrix[below] (b23) at (5,-4) {\times & \bullet\\};
\draw[blue] (b1-1-1.center) -- (t21-1-1.north east)
    (b1-1-4.center) -- (t22-1-3.north)
    (b1-1-5.center) -- (t23-1-1.north west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

完整图表:类似

\documentclass[tikz,margin=1mm]{standalone}
\usetikzlibrary{matrix}
\tikzset{
    every matrix/.style={
        inner sep=-\pgflinewidth,
        matrix of math nodes,
        column sep=-\pgflinewidth,
        nodes={
            draw=red,
            font=\color{blue},
            minimum size=.75cm,
            anchor=center
        }
    }
}
\begin{document}
\begin{tikzpicture}
\matrix[above] (t1) at (0,0) {18 & 44 & 76 & 198\\};
\matrix[below] (b1) at (0,0) {\bullet & \times & \times & \bullet & \bullet\\};
\matrix[above] (t21) at (-5,-4) {7 & 12\\};
\matrix[below] (b21) at (-5,-4) {\times & \bullet & \times\\};
\matrix[above] (t22) at (0,-4) {80 & 92 & 141\\};
\matrix[below] (b22) at (0,-4) {\bullet & \times & \times & \bullet\\};
\matrix[above] (t23) at (5,-4) {262\\};
\matrix[below] (b23) at (5,-4) {\times & \bullet\\};
\matrix[above] (t31) at (-7.5,-8) {8 & 10\\};
\matrix[below] (b31) at (-7.5,-8) {\times & \times & \times\\};
\matrix[above] (t32) at (-2.5,-8) {77\\};
\matrix[below] (b32) at (-2.5,-8) {\times & \times\\};
\matrix[above] (t33) at (2.5,-8) {148 & 151 & 172 & 186\\};
\matrix[below] (b33) at (2.5,-8) {\times & \times & \times & \times & \times\\};
\matrix[above] (t34) at (7.5,-8) {272 & 286 & 350\\};
\matrix[below] (b34) at (7.5,-8) {\times & \times & \times & \times\\};
\draw[blue] (b1-1-1.center) -- (t21-1-1.north east)
    (b1-1-4.center) -- (t22-1-3.north)
    (b1-1-5.center) -- (t23-1-1.north west)
    (b21-1-2.center) -- (t31-1-1.north east)
    (b22-1-1.center) -- (t32-1-1.north)
    (b22-1-4.center) -- (t33-1-2.north east)
    (b23-1-2.center) -- (t34-1-3.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容