BTree 之间的箭头

BTree 之间的箭头

我有一个用 TiKz 制作的 BTree,在其中添加了一个新元素。然后必须转换 BTree。我想让它看起来像示例图片:

带插入功能的 BTree

但我不知道如何实现?编辑:我想在下面的示例中将箭头插入右箭头所在的位置

\documentclass[11pt,a4paper]{文章}
\usepackage[utf8]{输入框}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{形状}

\usepackage[左=2cm,右=2cm,上=2cm,下=2cm]{几何}
\开始{文档}

\开始{tikzpicture}
\tikzstyle{bplus}=[
    矩形分割,
    水平分割的矩形,
    矩形分割部分 = 3,
]
\tikzstyle{每个节点}=[bplus]
\tikzstyle{级别 1}=[兄弟距离=20mm]
\node {5 \nodepart{二} 6 \nodepart{三} 33}
\end{tikzpicture} $\Rightarrow$
\开始{tikzpicture}
\tikzstyle{bplus}=[
    矩形分割,
    水平分割的矩形,
    矩形分割部分 = 3,
]
\tikzstyle{每个节点}=[bplus]
\tikzstyle{级别 1}=[兄弟距离=20mm]
\node {5 \nodepart{二} 6 \nodepart{三} 33}
\结束{tikzpicture}


\结束{文档}

带箭头的最小 BTree

答案1

两个例子:

在此处输入图片描述

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz,
           diagrams={>=Straight Barb},
           nodes={text depth=0.25ex}
           }

\begin{document}
\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]   
        &               \\ 
|[draw]| -5,-1,0 
    & |[draw]| 2 
        & |[draw]| 6,7,12 
\end{tikzcd} \begin{tikzcd}\ar[r,"\text{insert 3}",Rightarrow]&~\end{tikzcd}
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}

\bigskip 

\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} $\xRightarrow{\text{insert 3}}$
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0

这是您想要实现的吗?还是应该在底行的节点之间画箭头?

在此处输入图片描述


\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz,
           diagrams={>=Straight Barb},
           nodes={text depth=0.25ex},
           }

\begin{document}
\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} \begin{tikzcd} &   \\[5ex]
                            \ar[r,"\text{insert 3}",Rightarrow]&~\end{tikzcd}
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}

\bigskip
\begin{tikzcd}[column sep=tiny,baseline={([yshift=1ex]current bounding box.south)}]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} $\xRightarrow{\text{insert 3}}$
    \begin{tikzcd}[column sep=tiny,baseline={([yshift=1ex]current bounding box.south)}]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}
\end{document}

答案2

您可以使用 绘制树forest,并为节点设置基线multipart

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\usepackage[edges]{forest}
\usetikzlibrary{shapes.multipart}
\tikzset{bplus/.style={
    rectangle split, 
    rectangle split horizontal,
    rectangle split parts = #1, 
    draw
},bplus/.default=3}
\forestset{mtree/.style={for tree={draw,edge={-stealth}}}}
\begin{document}
$\vcenter{\hbox{\begin{forest}
  mtree
  [{1,5}
   [{-5,-1,0}]
   [{2}]
   [{6,7,12}]
  ]
\end{forest}}}\xRightarrow{\text{insert 3}}
\vcenter{\hbox{\begin{forest}
  mtree
  [{1,5}
   [{-5,-1,0}]
   [{2,3}]
   [{6,7,12}]
  ]
\end{forest}}}$
\bigskip

$\begin{tikzpicture}[baseline={(A.base)}]
\node[bplus](A){5 \nodepart{two} 6 \nodepart{three} 33};
\end{tikzpicture}\Longrightarrow
\begin{tikzpicture}[baseline={(B.base)}]
\node[bplus](B){5 \nodepart{two} 6 \nodepart{three} 33};
\end{tikzpicture}$
\end{document}

在此处输入图片描述

相关内容