我正在尝试绘制下图:
到目前为止我能做这么多:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,0) {(2,3)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (b) at (2,1) {(2,4)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,2) {(4,2)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,3) {(2,5)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,4) {(6,2)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,5) {(6,4)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (2,6) {(7,2)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (8,3) {(2,3)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (b) at (8,4) {(2,4)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (8,5) {(4,2)};
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm] (a) at (8,6) {(2,5)};
\node[draw,fill=Red!60,minimum width=3cm,minimum height=1cm] (a) at (14,3) {(2,3)};
\node[draw,fill=Red!60,minimum width=3cm,minimum height=1cm] (b) at (14,4) {(2,4)};
\node[draw,fill=Red!60,minimum width=3cm,minimum height=1cm] (a) at (14,5) {(4,2)};
\node[draw,fill=Red!60,minimum width=3cm,minimum height=1cm] (a) at (14,6) {(2,5)};
\end{tikzpicture}
\end{document}
答案1
您可以使用括号装饰器来修饰括号,并为标签添加额外的节点。您还可以通过适当使用 来大大减少代码中的冗余\foreach
。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[decoration={brace,amplitude=2mm,mirror},]
\foreach[count=\i] \x/\y in {7/2,6/4,6/2,2/5,4/2,2/4,2/3}
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm,below] (a) at (2,-\i) {(\x,\y)};
\foreach[count=\i] \x/\y in {2/5,4/2,2/4,2/3}{
\node[draw,fill=LightSteelBlue!60,minimum width=3cm,minimum height=1cm,below] (b) at (8,-\i) {(\x,\y)};
\node[draw,fill=Red!60,minimum width=3cm,minimum height=1cm,below] (c) at (14,-\i) {(\x,\y)};
}
\draw [decorate] (0.3,-1) --node[left=3mm]{$S_1$} (0.3,-3);
\draw [decorate] (0.3,-4) --node[left=3mm]{$S_2$} (0.3,-6);
\node[align=center,below] at (2,-9) (alabel) {$S$\\ explicit};
\node[align=center,below] at (8,-6) (blabel) {$S'$\\ used};
\node[align=center,below] at (14,-6) (clabel) {$T$};
\draw[->]
(a) edge (alabel)
(b) edge (blabel)
(c) edge (clabel)
;
\end{tikzpicture}
\end{document}