我正在尝试将数据结构中的数组的空单元格与已填充单元格对齐。请帮忙!!这是我目前拥有的代码:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
nodes in empty cells,
row 1/.style={nodes={draw=none}},]
{
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
2 & 4 & 4 & 5 & & & & &\\
};
\end{tikzpicture}
\end{document}
结果如下:
我想把盒子排列整齐,该怎么做呢???
答案1
您需要定义节点的锚点
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{backgrounds, matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm, anchor=south}, % <-- added anchor
column sep=-\pgflinewidth, row sep=-\pgflinewidth, % <-- for overlaps cells borders
nodes in empty cells,
row 1/.style={nodes={draw=none}}
]
{
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
2 & 4 & 4 & 5 & & & & \\
};
\end{tikzpicture}
\end{document}