答案1
你的方法嵌套了tikzpicture
s,这是不支持的。相反,你可以使用path picture
节点来绘制网格。此外,我建议forest
绘制树(但grid
下面定义的节点样式在普通 Ti 中有效钾当然还有 Z)。
\documentclass{article}
\usepackage{forest}
\tikzset{grid/.style args={#1/#2}{draw,minimum height=1ex,minimum width=#1*1ex,
path picture={\foreach \XX in {1,...,\the\numexpr#1-1}
{\draw ([xshift=\XX*1ex]path picture bounding box.south west) --
([xshift=\XX*1ex]path picture bounding box.north west);
}
\ifnum#2>0
\foreach \XX in {1,...,#2}
{\fill ([xshift=1ex-\XX*1ex]path picture bounding box.south east) rectangle
([xshift=-\XX*1ex]path picture bounding box.north east);
}
\fi
}}}
\begin{document}
\begin{forest}
[,grid=5/2,
[,grid=3/0]
[,grid=3/0]
]
\end{forest}
\end{document}