答案1
不需要使用 TikZ,tabularray
就足够了:
\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularray}
\begin{document}
\begin{figure}\centering
\begin{tblr}{
column{1-Y}={20pt, c, colsep=3pt, font={\bfseries}},
column{Z}={l, font={\bfseries}},
row{2-Z}={20pt, m},
hline{2,Z}={1-Y}{1.5pt,solid},
hline{3} ={1}{1-Y}{1.5pt,solid},
hline{3} ={2}{1-Y}{1.5pt,solid},
rulesep=10pt,
abovesep=4.5pt,
belowsep=1.5pt,
vline{1-Y}={2,3}{1.5pt, solid}
}
0&1&2&3&4&5&6&7&8&9&\\
0&0&1&0&0&0&0&0&0&0&B\\
0&2&5&6&6&8&8&9&10&10&count\\
\end{tblr}
\caption{For $i=1$}
\end{figure}
\end{document}
答案2
有很多方法可以做到这一点。这是 TikZ 解决方案。\foreach
如果您愿意,可以向列表中添加其他数据。
\documentclass{article}
\usepackage{tikz}
\tikzset{box/.style={draw, thick, minimum width=1cm, minimum height=1cm}}
\begin{document}
\begin{tikzpicture}[font=\sffamily\bfseries]
\foreach \b/\c[count=\n, evaluate=\n as \m using int(\n-1)] in {0/0,0/2,1/5,0/6,0/6,0/8,0/8,0/9,0/10,0/10}{
\node[box,label=above:\m] at (\n,1.5){\b};
\node[box] at (\n,0){\c};
\xdef\lastn{\n}
}
\node[right] at (.5+\lastn,1.5){B};
\node[right] at (.5+\lastn,0){count};
\end{tikzpicture}
\end{document}