How to use simple example for drawing an array in tikz

by Anush   Last Updated August 13, 2019 18:23 PM

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?

Tags : tikz-pgf beamer


Answers 1


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}
Torbjørn T.
Torbjørn T.
August 13, 2019 17:58 PM

Related Questions


Updated March 15, 2019 09:23 AM

Updated May 20, 2016 08:09 AM

Updated July 12, 2018 00:23 AM

Updated July 13, 2018 12:23 PM