1

I want to reproduce the following image with tikz

grid of thread blocks

Currently I've defined three classes of nodes: grid, block, thread. I'm slowly putting them one next to the other. Is there some advanced technique to speed this process up? Because I'm even building it following this answer for putting the text above. I was thinking maybe if somebody knows some way to generate a rectangle from the index (i,j) as input, with the text placed above.

P.S. Please add some tags if needed, I'm new to this community

Eugenio
  • 219
  • 2
    It would be helpful to show us what you have tried. Posting a minimal working example that makes it easier for people to suggest improvements It also makes it easier for people to help you, since they have some code to start from and, hence, much more likely that some one will try to help you. –  Feb 10 '17 at 01:44
  • If I wanted to produce pictures like these then I would define them using pics. For example, see http://tex.stackexchange.com/questions/340546/complex-line-diagrams-inside-tikz/340565#340565. –  Feb 10 '17 at 01:45
  • 2
    It depends on what you mean by faster? Development time, execution time, or reproduction time. – John Kormylo Feb 10 '17 at 01:48

1 Answers1

1

If you don't mind a wrong numbering, you can do it with two pics, two matrix and two fit nodes.

The snake arrow is from https://tex.stackexchange.com/a/145101/1952

\documentclass[a4paper,12pt]{amsart}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fit, backgrounds, arrows, calc, decorations.pathmorphing, positioning}
\tikzset{%
    snake arrow/.style=
        {->, thick,
        decorate,
        decoration={snake,
            amplitude=.4mm,
            segment length=2mm,
            post length=1mm}},
    thread/.pic={
        \node[fill=orange,      
            label={[anchor=north, 
                        name=th]90:Thread (\the\pgfmatrixcurrentcolumn,\the\pgfmatrixcurrentrow)}, 
            minimum width=3cm, 
            minimum height=2.5cm, 
            draw] (Th) {};
        \draw[thick] (th.south) edge[snake arrow] ++(-90:15mm);
},
    block/.pic={
        \node[fill=yellow,      
            label={[anchor=north, 
                        name=bl]90:Block (\the\pgfmatrixcurrentcolumn,\the\pgfmatrixcurrentrow)}, 
            minimum width=3cm, 
            minimum height=2.5cm, 
            draw] (Bl) {};
        \foreach \i in {-6,-4,...,6}\draw[thick] ([xshift=\i mm]bl.south) edge[snake arrow] ++(-90:15mm);
}

}


\begin{document}

\begin{tikzpicture}

\matrix[label={[anchor=south west, name=gl]north west:Grid}] (OneGrid) [column sep=1mm, row sep=1mm]
{\pic{block}; & \pic{block}; & \pic{block}; \\
\pic {block}; & \pic (Ref) {block}; & \pic{block}; \\
};
\begin{scope}[on background layer]
\node[fit=(OneGrid) (gl), inner sep=0pt, fill=green, draw=gray] (Grid) {};
\end{scope}


\matrix[label={[name=ml]Block(1,1)}, below=2cm of Grid] (OneBlock) [column sep=-\pgflinewidth, row sep=\pgflinewidth]
{\pic{thread}; & \pic{thread}; & \pic{thread}; & \pic{thread}; \\
\pic{thread}; & \pic{thread}; & \pic{thread}; & \pic{thread}; \\
\pic{thread}; & \pic{thread}; & \pic{thread}; & \pic{thread}; \\
};
\begin{scope}[on background layer]
\node[fit=(OneBlock) (ml), inner sep=0pt, fill=yellow, draw=gray] (Block) {};
\end{scope}

\draw[dashed] (RefBl.north west) -- (Block.north west);
\draw[dashed] (RefBl.north east) -- (Block.north east);

\end{tikzpicture}

\end{document}

enter image description here

Update: Thank you to TeXnician for reminding me about \numexpr.

Change \the\pgfmatrixcurrentcolumn by \the\numexpr\pgfmatrixcurrentcolumn-1 to start numbering from 0.

Ignasi
  • 136,588