我正在尝试了解如何绘制如下图表:
我希望能够单独指定每个可见方块的位置,而不是使用某种 TikZ 循环来定义位置。也许矩阵是一种好方法,但我不确定。
制作这样的图表的清晰且灵活的方法是什么?
答案1
不使用循环你也可以这样做。(但我认为循环很棒)。
创造grids
,nodes
, ...
\documentclass[tikz, border=30pt]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}
\draw[thick] (0,0.5)--(-1,0.5) node[anchor=east] {Aaa};
\draw[thick] (0,1.5)--(-1,1.5) node[anchor=east] {Bbb};
\draw[thick] (0,2.5)--(-1,2.5) node[anchor=east] {Ccc};
\draw[thick] (0,3.5)--(-1,3.5) node[anchor=east] {Ddd};
\draw[thick] (0,4.5)--(-1,4.5) node[anchor=east] {Eee};
\node [draw=none,anchor=south,red] at (0.5,5) {name} ;
\node [draw=none,anchor=south,blue] at (2.5,5) {name} ;
\node [draw=none,anchor=south] at (4.5,5) {name} ;
\node [draw=none,anchor=south,green] at (6.5,5) {name} ;
\node [draw=none,anchor=south,gray] at (8.5,5) {name} ;
\draw[step=1cm] (0,0) grid (1,5);
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (0,0) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (0,1) {};
\node[label={[label distance=0cm,xshift=0.5cm]90:{text}}] at (0,2) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (0,3) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (0,4) {};
\draw[step=1cm,yellow] (2,0) grid (3,5);
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (2,0) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (2,1) {};
\node[label={[label distance=0cm,xshift=0.5cm]90:{man}}] at (2,2) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (2,3) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (2,4) {};
\draw[step=1cm,green] (4,0) grid (5,5);
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (4,0) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (4,1) {};
\node[label={[label distance=0cm,xshift=0.5cm]90:{text}}] at (4,2) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (4,3) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (4,4) {};
\draw[step=1cm,blue] (6,0) grid (7,5);
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (6,0) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (6,1) {};
\node[label={[label distance=0cm,xshift=0.5cm]90:{man}}] at (6,2) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (6,3) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (6,4) {};
\draw[step=1cm,red] (8,0) grid (9,5);
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (8,0) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (8,1) {};
\node[label={[label distance=0cm,xshift=0.5cm]90:{man}}] at (8,2) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (8,3) {};
\node[label={[label distance=0cm,anchor=south,xshift=0.5cm]90:{text}}] at (8,4) {};
\end{tikzpicture} \end{document}