# How to use simple example for drawing an array in tikz

I would like to draw a simple array. I found this example. However it will not render for me:

\documentclass{beamer}
\usetheme{default}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc}
\begin{document}

\begin{frame}{Frame Title}
\begin{tikzpicture} [nodes in empty cells,
nodes={minimum width=0.5cm, minimum height=0.5cm},
row sep=-\pgflinewidth, column sep=-\pgflinewidth]
border/.style={draw}

\matrix(vector)[matrix of nodes,
row 1/.style={nodes={draw=none, minimum width=0.3cm}},
nodes={draw}]
{
\tiny{0} & \tiny{1} & \tiny{2} & \tiny{3}\\
$a_{0}$ & $a_{1}$ & $a_{2}$ & $a_{3}$\\
};
\end{tikzpicture}
\end{frame}

\end{document}


I get:

! Package pgfkeys Error: I do not know the key '/tikz/nodes in empty cells' and I am going to ignore it. Perhaps you misspelled it.

What am I doing wrong?

• Do you really need TikZ to draw such an array? – Bernard Aug 13 '19 at 18:08

You need to add the matrix TikZ-library, and take tikz matrix undefined control sequence into account.

\documentclass{beamer}
\usetheme{default}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, matrix} % <-- added library
\begin{document}

\begin{frame}{Frame Title}
\begin{tikzpicture} [nodes in empty cells,
nodes={minimum width=0.5cm, minimum height=0.5cm},
row sep=-\pgflinewidth, column sep=-\pgflinewidth]
%    border/.style={draw}

\matrix(vector)[matrix of nodes, ampersand replacement=\&, % <- added ampersand replacement
row 1/.style={nodes={draw=none, minimum width=0.3cm}},
nodes={draw}]
{ % use \& instead of & as column separator
\tiny{0} \& \tiny{1} \& \tiny{2} \& \tiny{3}\\
$a_{0}$ \& $a_{1}$ \& $a_{2}$ \& $a_{3}$\\
};
\end{tikzpicture}
\end{frame}

\end{document}

• I tried adding matrix but didn't realise the second trick! Thank you. – Anush Aug 13 '19 at 17:59
• @Anush You may have noticed that after adding the matrix library you got a different error message, indicating that adding the library fixed the error you mention in your question. – Torbjørn T. Aug 13 '19 at 18:00