使用 tikz 重现图像:高级编码可以加快进程吗?

使用 tikz 重现图像:高级编码可以加快进程吗?

我想用 tikz 重现以下图像

线程块网格

目前我已经定义了三类节点:网格、块、线程。我正在慢慢地把它们放在一起。有没有一些先进的技术可以加快这个过程?因为我甚至在构建它时遵循这个答案用于将文本放在上面。我在想,也许有人知道如何从索引 (i,j) 作为输入生成一个矩形,并将文本放在上面。

PS 如果需要的话请添加一些标签,我是这个社区的新手

答案1

如果您不介意编号错误,您可以使用两个pics、两个matrix和两个fit节点来完成。

来自snake arrowhttps://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}

在此处输入图片描述

更新:感谢 TeXnician 提醒我\numexpr

更改\the\pgfmatrixcurrentcolumn\the\numexpr\pgfmatrixcurrentcolumn-1从 0 开始编号。

相关内容