如何用 tikz 指定从节点开始的边之间的空间大小?

如何用 tikz 指定从节点开始的边之间的空间大小?

我正在试验 Petri 网,我想在从相同转换开始的两个弧之间添加一些水平空间。

我的代码:

\begin{tikzpicture}
% Styles
[node distance=1.3cm, on grid,>=stealth',bend angle=45,auto,
every place/.style={minimum size=6mm,thick,draw=blue,fill=white},
every transition/.style={thick,draw=black,fill=black,minimum height=1mm,minimum   width=6mm},
red place/.style={place,draw=red,fill=red!20},
every label/.style={red},
pre/.style={<-,shorten <=1pt,>=stealth',semithick},
post/.style={->,shorten >=1pt,>=stealth',semithick}]
% Drawing
\node [transition] (T0) [label=right:$T_0$] {};
\node [place] (P0) [below=of T0, label=right:$P_0$] {}
 edge [pre] (T0);
\node [transition] (T1) [below=of P0, label=right:$T_1$] {}
 edge [pre] (P0);
\node [place] (P1) [below=of T1, label=right:$P_1$] {}
 edge [pre] (T1);
\node [transition] (T2) [below=of P1, label=above right:$T_2$] {}
 edge [pre] (P1);
\node [place] (P2) [below left=of T2, label=left:$P_2$] {}
 edge [pre, bend right] (T2);
\node [place] (P4) [below right=of T2, label=above right:$P_4$] {}
 edge [pre, bend left] (T2);
\node [transition] (T3) [below=of P2, label=left:$T_3$] {}
 edge [pre] (P2);
\node [place] (P3) [below=of T3, label=left:$P_3$] {}
 edge [pre] (T3);
\node [transition] (T4) [below=of P4, label=left:$T_4$] {}
 edge [pre] (P4);
\node [transition] (T5) [right=of T4, label=right:$T_5$] {}
 edge [pre, bend right] (P4);
\end{tikzpicture}

产生这个:

从过渡开始的弧线没有水平空间

但我想要实现的只是这一点:

我想要实现的目标(来自 PN 教科书)

如何指定起始圆弧之间的水平间距才能达到第二张图所示的效果?

答案1

使用calc您可以指定的库($(T2)!0.5!(T2.west)$)($(T2)!0.5!(T2.east)$)您可以使用 0.5):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{petri,arrows,positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
% Styles
[node distance=1.3cm, bend angle=45,auto,
every place/.style={minimum size=6mm,thick,draw=blue,fill=white},
every transition/.style={thick,draw=black,fill=black,minimum height=1mm,minimum   width=6mm},
red place/.style={place,draw=red,fill=red!20},
every label/.style={red},
pre/.style={<-,shorten <=1pt,>=stealth',semithick},
post/.style={->,shorten >=1pt,>=stealth',semithick}]
% Drawing
\node [transition] (T2) [label=above right:$T_2$] {};
\node [place] (P2) [below left=of T2, label=left:$P_2$] {}
 edge [pre, bend right] ($(T2)!0.5!(T2.west)$);
\node [place] (P4) [below right=of T2, label=above right:$P_4$] {}
 edge [pre, bend left] ($(T2)!0.5!(T2.east)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

默认情况下,对节点的引用(T2)是对其中心的引用(T2.center)。因此,命令

\node [place] (P2) [below left=of T2, label=left:$P_2$] {}
 edge [pre, bend right] (T2);

绘制一个箭头,从(P2.center)(T2.center)停止在T2边界。您可以引入一个距离,引用特定的锚点,T2例如([xshift=-1mm]T2.south)

\documentclass[tikz,border=3mm]{standalone}

\usetikzlibrary{petri, positioning, arrows}

\begin{document}
\begin{tikzpicture}
% Styles
[node distance=1.3cm, on grid,>=stealth',bend angle=45,auto,
every place/.style={minimum size=6mm,thick,draw=blue,fill=white},
every transition/.style={thick,draw=black,fill=black,minimum height=1mm,minimum   width=6mm},
red place/.style={place,draw=red,fill=red!20},
every label/.style={red},
pre/.style={<-,shorten <=1pt,>=stealth',semithick},
post/.style={->,shorten >=1pt,>=stealth',semithick}]
% Drawing
\node [transition] (T0) [label=right:$T_0$] {};
\node [place] (P0) [below=of T0, label=right:$P_0$] {}
 edge [pre] (T0);
\node [transition] (T1) [below=of P0, label=right:$T_1$] {}
 edge [pre] (P0);
\node [place] (P1) [below=of T1, label=right:$P_1$] {}
 edge [pre] (T1);
\node [transition] (T2) [below=of P1, label=above right:$T_2$] {}
 edge [pre] (P1);
\node [place] (P2) [below left=of T2, label=left:$P_2$] {}
 edge [pre, bend right] ([xshift=-1mm]T2.south);
\node [place] (P4) [below right=of T2, label=above right:$P_4$] {}
 edge [pre, bend left] ([xshift=1mm]T2.south);
\node [transition] (T3) [below=of P2, label=left:$T_3$] {}
 edge [pre] (P2);
\node [place] (P3) [below=of T3, label=left:$P_3$] {}
 edge [pre] (T3);
\node [transition] (T4) [below=of P4, label=left:$T_4$] {}
 edge [pre] (P4);
\node [transition] (T5) [right=of T4, label=right:$T_5$] {}
 edge [pre, bend right] (P4);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

最快的解决方法是

\node [place] (P2) [below left=of T2, label=left:$P_2$] {} 
     edge [pre, bend right] ([xshift=-1mm]T2.south);
\node [place] (P4) [below right=of T2, label=above right:$P_4$] {} 
     edge [pre,bend left] ([xshift=1mm]T2.south);

修改目标点,或者你可以给bend left/right按键输入角度,例如 40

在此处输入图片描述

相关内容