# How to create 1D array structure using TikZ?

I'm trying to replicate the attached image. However, I'm not really sure what type of command or environment to use.

• Hi @R Mustang and welcome to TeX.SE. Are you looking for something specific? It could be a table, a TikZ figure, a matrix. Is the "Figure 4 ..." just the legend of the figure?
– FHZ
Commented Mar 29, 2022 at 19:56

No need to use TikZ, tabularray is enough:

\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}


There are many ways to do this. Here is a TikZ solution. You can add additional data to the \foreach list if you wish.

\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}