There's this image I want to reproduce using tikz
My main issue is the right one since I want to take advantage tikz's automatic stuff for drawing. As of now, this MWE is my best attempt:
\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\usetikzlibrary{calc}
\tikzset{%
controlcpu/.pic={
\node[fill=yellow,
label={[anchor=north,
name=cu]90:Control Unit},
minimum width=3cm,
minimum height=2.5cm,
draw] (CU) {};
},
controlgpu/.pic={
\node[fill=yellow,
minimum width=3mm,
minimum height=1mm,
draw] (CU) {};
},
cachecpu/.pic={
\node[fill=red,
label={[anchor=north,
name=cache]90:Cache},
minimum width=3cm,
minimum height=2.5cm,
draw] (CU) {};
},
cachegpu/.pic={
\node[fill=red,
minimum width=3mm,
minimum height=1mm,
draw] (CUGPU) {};
},
alucpu/.pic={
\node[fill=green,
label={[anchor=north,
name=alu]90:ALU},
minimum width=3cm,
minimum height=2.5cm,
draw] (ALUCPU) {};
},
alugpu/.pic={
\node[fill=green,
minimum width=0.3cm,
minimum height=0.2cm,
draw] (ALUGPU) {};
},
dram/.pic={
\node[fill=orange,
label={[anchor=north,
name=dr]90:DRAM},
minimum width=3cm,
minimum height=2.5cm,
draw] (DRAM) {};
}
}
\begin{document}
\begin{tikzpicture}
\matrix[] (GRID) [column sep=1mm, row sep=1mm]
{\pic{controlgpu}; & \pic{cachegpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; \\
\pic{controlgpu}; & \pic{cachegpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; & \pic{alugpu}; \\};
\end{tikzpicture}
\end{document}
This is quite ugly and the output is horrible, since I don't know how to put the controlgpu and cachegpu one on top of the other
Furthermore, I couldn't manage to take advantage of foreach: maybe because it instead requires a "positional" (nodes) approach?
My questions are two
- What's the most efficient way to reproduce it using tikz's matrix?
- Can it be done using
foreach? Isforeachrecommended for drawings like those?
For instance, here at the official guide is what I mean with the use of foreach to generate a matrix-like shaped tikzfigure.



