Petrinet:在 TikZ 中合并箭头

Petrinet:在 TikZ 中合并箭头

在采纳了 TikZ 专家的建议后,我实现了以下目标:

箭头未合并

我使用了节点上可用的锚点。但箭头没有合并。我咨询过以下答案:使用 TikZ 合并箭头,但他们没有帮助我。

如何像这样合并箭头:

箭头合并

我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum height = 1cm,
    minimum width  = 1cm
}}

\tikzset{circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size = 1cm
}}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  %\draw[My Grid] (-5,-5) grid (15,15);
  \node (r1) at (-4,4) [squarenode] {r1};
  \node[right=4cm of r1] (r2) [squarenode] {r2};
  \node[below=3cm of r1] (r3) [squarenode] {r3};
  \node[right=4cm of r3] (r4) [squarenode] {r4};
  \node[right=1.5cm of r1] (s2) [circlenode] {s2};
  \node[above=1cm of s2] (s1) [circlenode] {s1};
  \node[below=1cm of s2] (s3) [circlenode] {s3};
  \node[right=1.5cm of r3] (s4) [circlenode] {s4};
  \node[below=1cm of s4] (s5) [circlenode] {s5};
  \draw[fill=black] (s1.center) circle [radius=0.1cm];
  \draw[fill=black] (s5.center) circle [radius=0.1cm];
  \draw[->] (r1) -- (s2);
  \draw[->] (s2) -- (r2);
  \draw[->] (r3) -- (s4);
  \draw[->] (s4) -- (r4);
  \draw[->] (s1) to [out=180,in=90] (r1);
  \draw[->] (r1) to [bend right=45] (s3);
  \draw[->] (s3) to [bend right=45] (r2);
  \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
  \draw[->] (r3) to [out=90,in=180] (s3);
\end{tikzpicture}
\end{document} 

答案1

像这样 ?

\documentclass[tikz,border=5mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum height = 1cm,
    minimum width  = 1cm
}}

\tikzset{circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size = 1cm
}}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  %\draw[My Grid] (-5,-5) grid (15,15);
  \node (r1) at (-4,4) [squarenode] {r1};
  \node[right=4cm of r1] (r2) [squarenode] {r2};
  \node[below=3cm of r1] (r3) [squarenode] {r3};
  \node[right=4cm of r3] (r4) [squarenode] {r4};
  \node[right=1.5cm of r1] (s2) [circlenode] {s2};
  \node[above=1cm of s2] (s1) [circlenode] {s1};
  \node[below=1cm of s2] (s3) [circlenode] {s3};
  \node[right=1.5cm of r3] (s4) [circlenode] {s4};
  \node[below=1cm of s4] (s5) [circlenode] {s5};
  \draw[fill=black] (s1.center) circle [radius=0.1cm];
  \draw[fill=black] (s5.center) circle [radius=0.1cm];
  \draw[->] (r1) -- (s2);
  \draw[->] (s2) -- (r2);
  \draw[->] (r3) -- (s4);
  \draw[->] (s4) -- (r4);
  \draw[->] (s1) to [out=180,in=90] (r1);
  \draw[->] (r1) to [out=-90,in=180] (s3);% <--- same angle as (r3) to (s3)
  \draw[->] (s3) to [bend right=45] (r2);
  \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
  \draw[->] (r3) to [out=90,in=180] (s3);
\end{tikzpicture}
\end{document} 

截屏

答案2

arrows.meta可以自定义箭头,我会使所有连接统一。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum height = 1cm,
    minimum width  = 1cm
}}

\tikzset{circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size = 1cm
}}


\begin{document}
\begin{tikzpicture}[help lines/.style={very thin},My Grid/.style={help
lines,color=blue!50},>={Stealth[length=2mm,width=1.5mm]}]
  %\draw[My Grid] (-5,-5) grid (15,15);
  \node (r1) at (-4,4) [squarenode] {r1};
  \node[right=4cm of r1] (r2) [squarenode] {r2};
  \node[below=3cm of r1] (r3) [squarenode] {r3};
  \node[right=4cm of r3] (r4) [squarenode] {r4};
  \node[right=1.5cm of r1] (s2) [circlenode] {s2};
  \node[above=1cm of s2] (s1) [circlenode] {s1};
  \node[below=1cm of s2] (s3) [circlenode] {s3};
  \node[right=1.5cm of r3] (s4) [circlenode] {s4};
  \node[below=1cm of s4] (s5) [circlenode] {s5};
  \draw[fill=black] (s1.center) circle [radius=0.1cm];
  \draw[fill=black] (s5.center) circle [radius=0.1cm];
  \draw[->] (r1) -- (s2);
  \draw[->] (s2) -- (r2);
  \draw[->] (r3) -- (s4);
  \draw[->] (s4) -- (r4);
  \draw[->] (s1) to [out=180,in=90] (r1);
  \draw[->] (r1) to [out=-90,in=180] (s3);
  \draw[->] (s3) to [out=0,in=-90] (r2);
  \draw[->] (r2) to [out=90,in=00] node[auto,swap] {2} (s1);
  \draw[->] (r3) to [out=90,in=180] (s3);
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容