我想畫一個簡單的陣列。我找到了這個 例子。但它不會為我呈現:
\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”,我將忽略它。也許你拼錯了。
我究竟做錯了什麼?
答案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}