TIKZ - 将一个块转换为并行的多个块

TIKZ - 将一个块转换为并行的多个块

我有以下代码:

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\usepackage{textcomp}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}

\usetikzlibrary{arrows,
    chains,
    decorations.markings,
    shadows, shapes.arrows,shapes}

\begin{document}

\begin{tikzpicture}
\begin{scope}[start chain = going below,
  every node/.append style={on chain,fill opacity=0.8,draw,
  join},every join/.style={thick,-latex},
  cs/.style={minimum width=4.5cm,copy shadow={shadow scale=1, shadow xshift=0.5ex, shadow yshift=-0.5ex}}
  ]

 \node[fill=white] (N1) {\begin{tabular}{p{1cm}cp{1cm}}
    IOH\\
    & \enspace\tiny $K\times K$\quad\quad \quad & 
    \end{tabular}};

 \node[fill=orange] (N2) {\begin{tabular}{p{4cm}cp{1cm}}
    COI\\
    \qquad\enspace\tiny\quad\quad\quad\quad $K\times K$ 
      \end{tabular}};

 \node[fill=white] (N3) {\begin{tabular}{p{4cm}cp{4cm}}
    \qquad
    \end{tabular}};

 \node[fill=white] (N4) {\begin{tabular}{p{1cm}cp{1cm}}
   GOH &\\
   & \tiny $K\times K$ \enspace\enspace& 
  \end{tabular}};
\end{scope}  
 \path (N1) -- (N2) coordinate[pos=0.5] (aux);
 \path (N2) -- (N3) node[pos=0.5,right,font=\bfseries\itshape]{};
 \path (N3) -- (N4) node[pos=0.5,right,font=\bfseries\itshape]{};
\end{tikzpicture}
\end{document}

得到下图: 在此处输入图片描述

现在我想更改此代码以获取新的数据: 在此处输入图片描述

请注意,字符“N”上方出现了一个下括号。

答案1

在此处输入图片描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                decorations.pathreplacing,
                calligraphy,% has to be after decorations.pathreplacings
                }
\usepackage{textcomp}
\usepackage{array}

\begin{document}

\begin{tikzpicture}[
    node distance = 5mm and 7mm,
 start chain = going below,
  box/.style = {draw, fill=#1, minimum size=2em},
box/.default = white,
every edge/.style = {draw, -Latex},
   BC/.style = {decorate,
                decoration={calligraphic brace, amplitude=5pt,
                raise=1mm},
                very thick, pen colour=#1
                }
                    ]
    \begin{scope}[every node/.append style={on chain}]
\node (N1) [box]
            {\begin{tabular}{p{12mm} >{\tiny}c p{12mm}}
                 IOH    &               &   \\
                        & $K\times K$   &
            \end{tabular}};
\node (N2) [box=orange]
            {\begin{tabular}{p{12mm} >{\tiny}c p{12mm}}
                 COI    &               &   \\
                        & $K\times K$   &
            \end{tabular}};
\node (N3) [box, node font=\bfseries]  {A};
    \end{scope}
\node (N4) [box,below=11mm of N3]
            {\begin{tabular}{p{12mm} >{\tiny}c p{12mm}}
                 GOH    &               &   \\
                        & $K\times K$   &
            \end{tabular}};
\node (N3L) [box, node font=\bfseries, left=of N3] {A};
\node (N3R) [box, node font=\bfseries,right=of N3] {A};
%
\path   (N1) edge (N2)
        (N2) edge (N3)
        (N2) edge (N3L.north)
        (N2) edge (N3R.north);
\draw[BC]   (N3R.south east) -- node (aux) [below=2mm] {$N$} (N3L.south west);
\path[shorten >=1pt]    (aux -| N3L) edge (N4)
                        (aux)        edge (N4)
                        (aux -| N3R) edge (N4);
\draw[ultra thick, shorten <=1mm, shorten >=1mm, dotted]
        (N3L) edge[-]  (N3)
        (N3R) edge[-]  (N3);
\end{tikzpicture}
\end{document}

笔记:从你的 MWE 中,我删除了所有未使用的 TikZ 库和定义的样式并添加arrows.meta(用于箭头),以及decorations.pathreplacing用于calligraphy在节点下用文本“A”括起来的括号。

答案2

这是 Zarko 优秀代码的一个小变体。

Node 的内容定义为labels而不是tabulars。这样,必须声明节点的大小。

位置用库定义positioning并且没有chains使用。

第三行中的节点用一个节点声明matrix

所有边均使用 Zarko 的代码绘制,并适应第三行节点的新名称。

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                decorations.pathreplacing,
                calligraphy,% had to be after lib. decorations.pathreplacings
                matrix,
                positioning
                }
\usepackage{textcomp}

\begin{document}

\begin{tikzpicture}[
    node distance = 5mm,
    box/.style = {draw, fill=#1, minimum height=1cm, minimum width=4.5cm},
    box/.default = white,
    every edge/.style = {draw, -Latex},
   BC/.style = {decorate,
                decoration={calligraphic brace, amplitude=5pt,
                raise=1mm},
                very thick, pen colour=#1
                }
                    ]
 \node (N1) [box, label={[anchor=north west]north west:IOH},
                label={[anchor=south, font=\tiny]south:$K\times K$}]
            {};                   
 \node (N2) [box=orange, label={[anchor=north west]north west:COI},
                label={[anchor=south, font=\tiny]south:$K\times K$},
                below=of N1]
            {};
 \matrix (N3) [matrix of nodes, inner sep=0pt, nodes={minimum size=1cm, draw, anchor=center, node font=\bfseries, node contents=A}, nodes in empty cells, column sep=.5cm,
        below=of N2]{&&\\};
  \node (N4) [box, label={[anchor=north west]north west:GOH},
                label={[anchor=south, font=\tiny]south:$K\times K$},
                below=1cm of N3]
            {};
\path   (N1) edge (N2)
        (N2) edge (N3-1-1.north)
        (N2) edge (N3-1-2)
        (N2) edge (N3-1-3.north);
\draw[BC]   (N3.south east) -- node (aux) [below=2mm] {$N$} (N3.south west);
\path[shorten >=1pt]    (aux -| N3-1-1) edge (N4)
                        (aux)        edge (N4)
                        (aux -| N3-1-3) edge (N4);
\draw[ultra thick, shorten <=1mm, shorten >=1mm, dotted]
        (N3-1-1) edge[-]  (N3-1-2)
        (N3-1-2) edge[-]  (N3-1-3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容