是否可以制作一个 B+ 树,其中内部节点水平对齐,叶子垂直对齐?我目前拥有的代码是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{center} \begin{tikzpicture}
\tikzstyle{bplus}=[rectangle split, rectangle split,rectangle split ignore empty parts,draw]
\tikzstyle{every node}=[bplus]
\tikzstyle{level 1}=[sibling distance=45mm]
\tikzstyle{level 2}=[sibling distance=15mm]
\node {10 \nodepart{two} 19} [->]
child{ node{4 \nodepart{two} 7}
child{ node{1 \nodepart{two} 2 \nodepart{three} 3}}
child{ node{4 \nodepart{two} 5 \nodepart{three} 6}}
child{ node{7 \nodepart{two} 8 \nodepart{three} 9}}}
child{ node {13 \nodepart{two} 16}
child{ node{10 \nodepart{two} 11 \nodepart{three} 12}}
child{ node{13 \nodepart{two} 14 \nodepart{three} 15}}
child{ node{16 \nodepart{two} 17 \nodepart{three} 18}}}
child {node {22}
child{ node{19 \nodepart{two} 20 \nodepart{three} 21}}
child{ node{22 \nodepart{two} 23 \nodepart{three} 24 \nodepart{four} 25}}}
; \end{tikzpicture} \end{center}\end{document}
我尝试让叶子水平排列,但遗憾的是,这与我想要的效果正好相反 =(
答案1
编辑:似乎猜测你想要实现什么,就在最后 :-)。看看,这是否是你在寻找的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[
every node/.style = {rectangle split, rectangle split parts = 3,
draw, anchor=north},
HMPN/.style = {rectangle split horizontal,%HMPN: horizontal multi part node :-)
rectangle split parts = 2,
draw, anchor=north},
edge from parent fork down,
level 1/.style = {sibling distance=55mm},
level 2/.style = {sibling distance=15mm}
]
\node[HMPN] {10 \nodepart{two} 19} [->]
child{ node[HMPN]{4 \nodepart{two} 7}
child{ node{1 \nodepart{two} 2 \nodepart{three} 3}}
child{ node{4 \nodepart{two} 5 \nodepart{three} 6}}
child{ node{7 \nodepart{two} 8 \nodepart{three} 9}}}
child{ node[HMPN] {13 \nodepart{two} 16}
child{ node{10 \nodepart{two} 11 \nodepart{three} 12}}
child{ node{13 \nodepart{two} 14 \nodepart{three} 15}}
child{ node{16 \nodepart{two} 17 \nodepart{three} 18}}}
child {node[HMPN] {22}
child{ node{19 \nodepart{two} 20 \nodepart{three} 21}}
child{ node{22 \nodepart{two} 23 \nodepart{three} 24 \nodepart{four} 25}}};
\end{tikzpicture}
\end{center}
\end{document}
通过以上你应该得到: