![绘制具有多个输入和输出的节点的图形](https://linux22.com/image/371501/%E7%BB%98%E5%88%B6%E5%85%B7%E6%9C%89%E5%A4%9A%E4%B8%AA%E8%BE%93%E5%85%A5%E5%92%8C%E8%BE%93%E5%87%BA%E7%9A%84%E8%8A%82%E7%82%B9%E7%9A%84%E5%9B%BE%E5%BD%A2.png)
如何绘制一个图形,其中节点具有多个输入和输出,并且边连接各个输入和输出?如下图所示。
图像来源
答案1
\documentclass[tikz, border = 3pt]{standalone}
\usetikzlibrary{quotes}
\tikzset{
node23/.pic ={
\coordinate (A) at (0, 0);
\coordinate (B) at (2, 3.5);
\draw[pic actions] (A) rectangle (B) node [pos = 0.5]{\large\tikzpictext};
\foreach \y in {0.5, 1.5, 2.5} \fill[pic actions] (2, \y) rectangle (2.5, \y + 0.5);
\foreach \y in {0.75, 2.25} \fill[pic actions] (0, \y) rectangle (-0.5, \y + 0.5);
},
node12/.pic ={
\coordinate (A) at (0, 0);
\coordinate (B) at (2, 2.5);
\draw[pic actions] (A) rectangle (B) node [pos = 0.5]{\large\tikzpictext};
\foreach \y in {0.5, 1.5} \fill[pic actions] (2, \y) rectangle (2.5, \y + 0.5);
\foreach \y in {1.0} \fill[pic actions] (0, \y) rectangle (-0.5, \y + 0.5);
}
}
\begin{document}
\begin{tikzpicture}
\pic[color = red, "F"] (F) {node23};
\pic[color = blue , "r"] (r) at (4, 0) {node12};
\pic[color = orange , "G"] (G) at (8, 0) {node23};
\pic[color = cyan , "H"] (H) at (8, -4) {node23};
\draw[->] (2.6, 2.75) -- (3.4, 1.25);
\draw[->] (6.6, 1.75) -- (7.4, 2.50);
\draw[->] (6.6, 0.75) -- (7.4, -1.50);
\end{tikzpicture}
\end{document}