如何在 TikZ 框图中绘制不同的箭头

如何在 TikZ 框图中绘制不同的箭头

我想要这个图

我有以下代码,我想对它做一些类似的事情。你能帮我画箭头吗?...

\begin{tikzpicture}[
% GLOBAL CFG
font=\sf \scriptsize,
>=LaTeX,
cell/.style={rectangle, rounded corners=5mm, fill=green!15, draw,very thick,},
operator/.style={circle,draw,inner sep=-0.5pt,minimum height =0.5cm, fill=red!10, font = \large}, 
block/.style={draw, fill=green!15, rectangle, 
minimum height=2em, minimum width=4em, font = \large},
blockv/.style={draw, fill=magenta!30, rectangle, 
minimum height=2em, minimum width=4em, font = \large},
function/.style={ellipse, draw,inner sep=1pt},
ct/.style={circle,draw,line width = .75pt,minimum width=1cm,inner sep=1pt,},
gt/.style={rectangle,draw,minimum width=4mm,minimum height=3mm,inner sep=1pt},
dot/.style = {circle,fill, inner sep=0.01mm, fill=black!15, node contents={}},
dots/.style = {circle,fill, inner sep=0.1mm, fill=black!200, node contents={}},
mylabel/.style={font=\scriptsize\sffamily},
ArrowC1/.style={% Arrows with rounded corners
    rounded corners=.25cm,
    thick,
    },
ArrowC2/.style={% Arrows with big rounded corners
    rounded corners=.5cm,
    thick,
    },
alr/.style = {-Stealth, dotted, thick},
   arr/.style = {-Stealth},
]




\node[block, name = b1] {b1};
\node[block, below = 0.5cm of b1 ] (b2) {b2};
\node[block, below = 0.5cm of b2 ] (b3) {b3};
\node[block, right = 0.5cm of b1 ] (br1) {br1};
\node[block, below = 0.5cm of br1 ] (br2) {br2};
\node[block, below = 0.5cm of br2 ] (br3) {br3};
\node[blockv, left = 0.5cm of b1] (CX1) {CX};
\node[blockv, left = 0.5cm of b2] (CX2) {CX};
\node[blockv, left = 0.5cm of b3] (CX3) {CX};
\node[blockv, right = 0.5cm of br1] (CXr1) {CX};
\node[blockv, right = 0.5cm of br2] (CXr2) {CX};
\node[blockv, right = 0.5cm of br3] (CXr3) {CX};
\node (dot1) [dot,right= 0.25cm of br3]{};
\node (dot2) [dot,left= 0.25cm of b3]{};

\node[block, below = 0.8cm of dot1] (poolr1) {\shortstack{x \\x}};
\node[block, below = 0.8cm of dot2] (pool1) {\shortstack{x \\c}};
%\draw[ line width=0.30mm] (dot6) |- node[above, font = \Large]{$c_{t-1}$}(dot1);
%\draw[ line width=0.30mm] (dot6) |- node[above, font = \Large]{$c_{t-1}$}(dot1);
\draw[arr, line width=0.30mm] (b1) -- node[pos = 0.405]{}(CX1);
\draw[arr, line width=0.30mm] (b2) -- node[pos = 0.405]{}(CX2);
\draw[arr, line width=0.30mm] (b3) -- node[pos = 0.405]{}(CX3);
\draw[arr, line width=0.30mm] (br1) -- node[pos = 0.405]{}(CXr1);
\draw[arr, line width=0.30mm] (br2) -- node[pos = 0.405]{}(CXr2);
\draw[arr, line width=0.30mm] (br3) -- node[pos = 0.405]{}(CXr3);
\draw[alr, line width=0.30mm] (CX1) -- node[pos = 0.405]{}(CX2);
\draw[alr, line width=0.30mm] (CX2) -- node[pos = 0.405]{}(CX3);
\draw[alr, line width=0.30mm] (CXr1) -- node[pos = 0.405]{}(CXr2);
\draw[alr, line width=0.30mm] (CXr2) -- node[pos = 0.405]{}(CXr3);
%\draw[line width=0.30mm] (CX1) -- node[pos = 0.405]{}(dot3);

%\draw[arr, line width=0.30mm] (CX1) -|node{}(pool1);
\end{tikzpicture}

答案1

您可以使用fit库来绘制绿色框。您可以使用to运算符来制作平滑曲线。您可以使用将这些标签放置在这些曲线上的特定位置pos

在此处输入图片描述

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,fit,calc}

\begin{document}

\begin{tikzpicture}[
  % GLOBAL CFG
  font=\sf \scriptsize,
  >=Latex,
  cell/.style={rectangle, rounded corners=5mm, fill=green!15, draw,very thick,},
  operator/.style={circle,draw,inner sep=-0.5pt,minimum height =0.5cm, fill=red!10, font = \large}, 
  block/.style={draw, fill=green!15, rectangle, 
    minimum height=2em, minimum width=4em, font = \large},
  blockv/.style={draw, fill=magenta!30, rectangle, 
    minimum height=2em, minimum width=4em, font = \large},
  function/.style={ellipse, draw,inner sep=1pt},
  ct/.style={circle,draw,line width = .75pt,minimum width=1cm,inner sep=1pt,},
  gt/.style={rectangle,draw,minimum width=4mm,minimum height=3mm,inner sep=1pt},
  dot/.style = {circle,fill, inner sep=0.01mm, fill=black!15, node contents={}},
  dots/.style = {circle,fill, inner sep=0.1mm, fill=black!200, node contents={}},
  mylabel/.style={font=\scriptsize\sffamily},
  ArrowC1/.style={% Arrows with rounded corners
    rounded corners=.25cm,
    thick,
  },
  ArrowC2/.style={% Arrows with big rounded corners
    rounded corners=.5cm,
    thick,
  },
  alr/.style = {-Stealth, dotted, thick},
  arr/.style = {-Stealth},
  left connector/.style={out=180, in=180, looseness=1.5},
  right connector/.style={out=0, in=0, looseness=1.5}
  ]




  \node[block, name = b1] {b1};
  \node[block, below = 0.5cm of b1 ] (b2) {b2};
  \node[block, below = 0.5cm of b2 ] (b3) {b3};
  \node[block, right = 0.5cm of b1 ] (br1) {br1};
  \node[block, below = 0.5cm of br1 ] (br2) {br2};
  \node[block, below = 0.5cm of br2 ] (br3) {br3};
  \node[blockv, left = 0.5cm of b1] (CX1) {CX};
  \node[blockv, left = 0.5cm of b2] (CX2) {CX};
  \node[blockv, left = 0.5cm of b3] (CX3) {CX};
  \node[blockv, right = 0.5cm of br1] (CXr1) {CX};
  \node[blockv, right = 0.5cm of br2] (CXr2) {CX};
  \node[blockv, right = 0.5cm of br3] (CXr3) {CX};
  \node (dot1) [dot,right= 0.25cm of br3]{};
  \node (dot2) [dot,left= 0.25cm of b3]{};

  \node[block, below = 0.8cm of dot1] (poolr1) {\shortstack{x \\x}};
  \node[block, below = 0.8cm of dot2] (pool1) {\shortstack{x \\c}};
  % \draw[ line width=0.30mm] (dot6) |- node[above, font = \Large]{$c_{t-1}$}(dot1);
  % \draw[ line width=0.30mm] (dot6) |- node[above, font = \Large]{$c_{t-1}$}(dot1);
  \draw[arr, line width=0.30mm] (b1) -- node[pos = 0.405]{}(CX1);
  \draw[arr, line width=0.30mm] (b2) -- node[pos = 0.405]{}(CX2);
  \draw[arr, line width=0.30mm] (b3) -- node[pos = 0.405]{}(CX3);
  \draw[arr, line width=0.30mm] (br1) -- node[pos = 0.405]{}(CXr1);
  \draw[arr, line width=0.30mm] (br2) -- node[pos = 0.405]{}(CXr2);
  \draw[arr, line width=0.30mm] (br3) -- node[pos = 0.405]{}(CXr3);
  \draw[alr, line width=0.30mm] (CX1) -- node[pos = 0.405]{}(CX2);
  \draw[alr, line width=0.30mm] (CX2) -- node[pos = 0.405]{}(CX3);
  \draw[alr, line width=0.30mm] (CXr1) -- node[pos = 0.405]{}(CXr2);
  \draw[alr, line width=0.30mm] (CXr2) -- node[pos = 0.405]{}(CXr3);
  % \draw[line width=0.30mm] (CX1) -- node[pos = 0.405]{}(dot3);

  % \draw[arr, line width=0.30mm] (CX1) -|node{}(pool1);

  \node [fit=(CX1)(b3), draw, green, label={[above]A}] {};
  \node [fit=(CXr1)(br3), draw, green, label={[above]B}] {};

  \draw [->] (CX1) to [left connector] node [near start, above left] {f} ($(pool1.west) - (0,4pt)$);
  \draw [->] (CX2) to [left connector] node [near start, above left] {g} (pool1.west);
  \draw [->] (CX3) to [left connector] ($(pool1.west) + (0,4pt)$);

  \draw [->] (CXr1) to [right connector] node [near start, above right] {h} ($(poolr1.east) - (0,4pt)$);
  \draw [->] (CXr2) to [right connector] (poolr1.east);
  \draw [->] (CXr3) to [right connector] ($(poolr1.east) + (0,4pt)$);
\end{tikzpicture}

\end{document}

答案2

使用chains库:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                fit,
                positioning,
                quotes}
\makeatletter
\tikzset{suspend join/.code = \def\tikz@after@path{}}
\makeatother

\begin{document}
    \begin{tikzpicture}[auto=right,
node distance = 5mm and 5mm,
  start chain = going below,
   ard/.style = {semithick, densely dotted,-Stealth},
   arr/.style = {semithick, rounded corners=3mm, -Stealth},
   box/.style = {draw, fill=#1,
                 minimum height=2em, minimum width=4em,
                 font=\large},
   FIT/.style = {draw, green, fit=#1},
                        ]
%% nodes
    \begin{scope}[nodes={box=green!30, on chain}]
\node   (b1) {b1};
\node   (b2) {b2};
\node   (b3) {b3};
\node   (br1)   [right=of b1]   {br1};
\node   (br2)   [right=of b2]   {br1};
\node   (br3)   [right=of b3]   {br1};
    \end{scope}
    \begin{scope}[nodes={box=red!30, on chain, join=by ard}]
\node   (CX1)   [suspend join,
                 left=of b1]    {CX};
\node   (CX2)   {CX};
\node   (CX3)   {CX};
%
\node   (CXr1)  [suspend join,
                 right = 0.5cm of br1]  {CX};
\node   (CXr2)  {CX};
\node   (CXr3)  {CX};
    \end{scope}
%
\node   (fL)    [FIT=(CX1)  (b3), label=A] {};
\node   (fR)    [FIT=(CXr1)(br3), label=B] {};
%
\node    (pool1)    [box=green!30, below=of fL] {\shortstack{x \\c}};
\node    (poolr1)   [box=green!30, below=of fR] {\shortstack{x \\x}};
%%
\foreach\i in {1,2,3}
{
\draw[arr] (b\i)  -- (CX\i);
\draw[arr] (br\i) -- (CXr\i);
}
%%
    \begin{scope}[every path/.style = {arr}]
\draw   (CX1.west) to ["f"] ++ (-9mm,0) |- ([yshift=-4pt] pool1.west);
\draw   (CX2.west) to ["g"] ++ (-5mm,0) |- (pool1.west);
\draw   (CX3.west) -- ++ (-3mm,0) |- ([yshift= 4pt] pool1.west);
%
\draw   (CXr1.east) to ["h" '] ++ (7mm,0) |- ([yshift=-4pt] poolr1.east);
\draw   (CXr2.east) -- ++ (5mm,0) |- (poolr1.east);
\draw   (CXr3.east) -- ++ (3mm,0) |- ([yshift= 4pt] poolr1.east);
    \end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容