如何在 TikZ 中用箭头绘制相邻单元格?

如何在 TikZ 中用箭头绘制相邻单元格?

我想绘制下面的图表。我该如何绘制这个图表?

在此处输入图片描述

我没有找到任何示例来重现上述图像。

答案1

开始一些事情

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{matrix,positioning}

\tikzset{
    blockline/.style={matrix of nodes, nodes in empty cells,
        row sep=0pt, column sep=-\pgflinewidth,
        nodes={anchor=center, minimum width=15mm, minimum height=8mm},},
}

\begin{document}

\begin{tikzpicture}

\matrix[blockline] (block1a) {
&|[draw]| &|[draw, label=block1a]| 500 &|[draw]| &\\ 0 & 1 & 2 & 3 & 4\\};
\draw ([yshift=-.5\pgflinewidth]block1a-1-1.north west)--([yshift=-.5\pgflinewidth]block1a-1-5.north east) ([yshift=.5\pgflinewidth]block1a-1-1.south west)--([yshift=.5\pgflinewidth]block1a-1-5.south east);

\matrix[blockline, below right=0mm and 10mm of block1a.south] (block2a) {
&|[draw]| &|[draw, label=block2a]| 502 &|[draw]| &\\ 23 & 24 & 25 & 26 & 27\\};
\draw ([yshift=-.5\pgflinewidth]block2a-1-1.north west)--([yshift=-.5\pgflinewidth]block2a-1-5.north east) ([yshift=.5\pgflinewidth]block2a-1-1.south west)--([yshift=.5\pgflinewidth]block2a-1-5.south east);

\draw[->] ([xshift=5mm]block1a-1-3.south) coordinate(aux)-- node[pos=.35,right]{right} (aux|-block2a.south)-|([xshift=-5mm]block2a-1-3.south);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

这是一个起点:

\documentclass[tikz,border=3.14159pt]{standalone}

\usetikzlibrary{matrix,positioning,arrows,arrows.meta,calc}

\tikzset{
    mymat/.style={
          matrix of nodes,
          anchor=center,
          row 2/.style={nodes=draw,nodes in empty cells},
          text height=2.8ex,
          text depth=0.75ex,
          text width=7ex,
          align=center,
          column sep=-\pgflinewidth
          },
    myarrow/.style={-{Stealth[scale=1.5]},rounded corners=2pt}
    }

\begin{document}
    \begin{tikzpicture}
        \matrix[mymat]
        at (0,0) 
        (mat1)
        {
         & & \small{block1a} & & \\
          &   & \large{500} &   &   \\
        0 & 1 & 2 & 3 & 4 \\
        };
        
        \matrix[mymat]
        at (-4,-3) 
        (mat2)
        {
         & & \small{block3a} & & \\
          &   & \large{501} &   &   \\
        11 & 12 & 13 & 14 & 15 \\
        };
        
        \draw[myarrow]
            ($(mat1-2-3.south)+(-.4,0)$) --++ (0,-4) node[left,pos=0.3]{left} -| ($(mat2-2-3.south)+(.4,0)$);
    \end{tikzpicture}
\end{document}

数据结构

相关内容