如何在 tikz 中将三个链连接在一起?

如何在 tikz 中将三个链连接在一起?

如何连接三条链?我想使用 tikz 绘制下图:

我想要绘制的图表

不幸的是,在我的系统中,以下代码的编译无法完成。如何使用链绘制上图?要么是分支,要么是三个相互连接的独立链。考虑以下 MWE:

 \documentclass[tikz,border=3mm]{standalone}
 \usepackage{listofitems}
 \usetikzlibrary{arrows.meta,bending,chains,decorations.markings}


 \tikzset{% 
   attach arrow/.style={
   decoration={
    markings,
     mark=at position 0 with {\pgfextra{%
     \pgfmathsetmacro{\tmpArrowTime}{\pgfkeysvalueof{/tikz/arc 
    arrow/length}/(\pgfdecoratedpathlength)}%
     \xdef\tmpArrowTime{\tmpArrowTime}}},
    mark=at position {#1-3*\tmpArrowTime} with {\coordinate(@1);},
    mark=at position {#1-2*\tmpArrowTime} with {\coordinate(@2);},
    mark=at position {#1-1*\tmpArrowTime} with {\coordinate(@3);},
    mark=at position {#1+\tmpArrowTime/2} with {\coordinate(@4);
    \draw[-{Stealth[length=\pgfkeysvalueof{/tikz/arc 
  arrow/length},bend]}] plot[smooth]
     coordinates {(@1) (@2) (@3) (@4)};},
    },
 postaction=decorate,
 },
 attach arrow/.default=0.5,
 arc arrow/.cd,length/.initial=2mm,
 }

 \begin{document}
 \readlist*\myarray{A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,Q}

 \begin{tikzpicture}[font=\sffamily,>={Stealth[bend]},
   block/.style={draw, rectangle,minimum height=1.6em,minimum width=9em,
   rotate=90,},decide/.code={\ifnum#1<7
    \tikzset{execute at begin node={ }}
   \else
   \tikzset{execute at begin node={}}
   \fi}]
   \begin{scope}[start chain=A placed {at={(\tikzchaincount*3em,0)}},
   nodes={on chain,block,join= by {thick,->},decide=\tikzchaincount}]
    \path foreach \X in {1,...,17}{node[fill=gray](A\X){\myarray[\X]}};
   \end{scope}

 \begin{scope}[start chain=B placed {at={(\tikzchaincount*3em,4)}},
   nodes={on chain,block,join= by {thick,->},decide=\tikzchaincount}]
   \path foreach \X in {1,...,17}{node[fill=gray]{\myarray[\X]}};
 \end{scope}

 \begin{scope}[start chain=C placed {at={(\tikzchaincount*3em+15,2)}},
     nodes={on chain,circle,decide=\tikzchaincount}]
    \path foreach \X in {1,...,16}{node[fill=gray](CS\X){CS}};
    \path foreach \X in {1,...,16}{ \draw[thin, ->] (A\X)-- (CS\X};
 \end{scope}


 \path (A-1.north) -- ++ (-1em,2) node[anchor=south,rotate=90](pool){}
    -- ++ (-0.5em,0) node[block,anchor=south,fill=gray](A-0)
      { Input 310};

   \draw[thick, ->] (A-0) -- (B-1);
   \draw[thick, ->] (A-0) -- (A-1);

   \end{tikzpicture}
   \end{document}

我想从第一个链连接到中间的圆形链,再从圆形链连接到第一个链中的下一个元素。同样,从第三个链连接到中间的圆形链。

编辑:以前,上述代码在我的系统上完全编译。现在,无论花多长时间,它的编译都无法完成。

答案1

  • 我不清楚你的问题是什么:
    • 使用一些(简单的)代码或
    • 修复了你的代码(我必须承认我迷失了)
  • 显示的图像我可以使用以下(非常简单的)MWE 重现:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                bending,
                chains,
                positioning
                }

\tikzset{%
 node distance = 22mm and 22mm,
   start chain = A going right,
   start chain = B going right,
   start chain = C going right,
    arr/.style = {-Stealth},
   boxA/.style = {draw, minimum size=11mm, font=\sffamily,
                  on chain=A, join=by arr},
   boxB/.style = {draw, minimum size=11mm, font=\sffamily,
                  on chain=B, join=by arr},
      C/.style = {circle, draw, minimum size=11mm,
                  on chain=C},
every edge/.append style={draw, -{Stealth[bend]}, bend angle=30}
        }

\begin{document}
    \begin{tikzpicture}
\foreach \i in {1, 2, 3}    
    \node   [boxA]  {A\i};

    \node   [boxB, below=of A-1]  {B1};
\foreach \i in {2, 3}
    \node   [boxB]  {B\i};
\path (A-1) -- node [C] {C1} (B-2);
\node               [C] {C2};
%%%%
\scoped[bend left]
\path   (A-1) edge (C-1) (C-1) edge (A-2)   
        (A-2) edge (C-2) (C-2) edge (A-3); 
\scoped[bend right]
\path   
(B-1) edge (C-1) (C-1) edge (B-2)
        (B-2) edge (C-2) (C-2) edge (B-3);
           \end{tikzpicture}
\end{document}

在此处输入图片描述

附录: 如果节点链较长且节点是矩形而不是正方形,则以下代码会更好:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                bending,
                chains,
                positioning
                }

\tikzset{%
 node distance = 22mm and 32mm, on grid, % <---
   start chain = A going right,
   start chain = B going right,
   start chain = C going right,
    arr/.style = {-Stealth},
   base/.style = {draw, minimum height=8mm, minimum width=12mm, % <---
                  font=\sffamily},
   boxA/.style = {base, on chain=A, join=by arr},
   boxB/.style = {base, on chain=B, join=by arr},
      C/.style = {circle, draw, minimum size=8mm,
                  on chain=C},
every edge/.append style={draw, -{Stealth[bend]}}
        }

\begin{document}
    \begin{tikzpicture}
\def\NumA{5}                % number of nodes in chains A and B
\def\NumB{\numexpr\NumA-1}  % number of nodes in chain C

\foreach \i in {1, ...,\NumA}    
    \node   [boxA]  {A\i};

    \node   [boxB, below=of A-1]  {B1};
\foreach \i in {2, ...,\NumA}
    \node   [boxB]  {B\i};
\path (A-1) -- node [C] {C1} (B-2);
\foreach \i in {2, ...,\NumB}
\node               [C] {C\i};
%%%%
\scoped[bend left=25]
{\foreach \i [count=\j from 2] in {1,...,\NumB}
\path   (A-\i) edge (C-\i) (C-\i) edge[bend left] (A-\j);
} 
\scoped[bend right=25]
{\foreach \i [count=\j from 2]  in {1,...,\NumB}
\path   (B-\i) edge (C-\i)    (C-\i) edge (B-\j);
}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容