我想画一个简单的数组。我找到了这个 例子。但是它不会为我呈现:
\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}
我得到:
!包 pgfkeys 错误:我不知道键 '/tikz/nodes in empty cells',我将忽略它。也许你拼错了。
我究竟做错了什么?
答案1
您需要添加matrix
TikZ 库,然后tikz矩阵未定义控制序列考虑在内。
\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}