我想知道如何使用 tikz 在 Petri 网中重新创建节点之间的边,如下所示:
我尝试了不同的选项但还是无法正确完成。
我尝试将其集成到的最小代码示例如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,shapes,automata,petri,positioning}
\tikzset{
place/.style={
circle,
thick,
draw=black!75,
%fill=white!20,
minimum size=6mm,
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
}
}
\begin{document}
\begin{tikzpicture}[node distance=0.4cm and 1cm,>=stealth',bend angle=45,auto]
\node [transitionV,label=above:$T_1$] (t1) {};
\node [place,tokens=1,label=above:$P_2$] (p2) [right=of t1] {}
edge[pre] (t1);
\end{tikzpicture}
\end{document}
生成如下图像:
但是我不知道如何在 tikz 中创建一个中间有交叉点并且在附近有一个标签的边缘样式,与第一个图形(以红色选择)上的类似?
答案1
定义装饰风格,例如
markedge/.style={
decoration={ markings,
mark=at position .5 with {\draw[-,thick] (-2mm,2mm) -- (2mm,-2mm)node[inner sep=1pt,pos=0.5,auto]{#1};} %% adjust 2mm etc as you wish
},
postaction={decorate}
},
然后像使用它一样
....edge[pre,markedge={2}] (t1);
这需要\usetikzlibrary{decorations.markings}
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,shapes,automata,petri,positioning,decorations.markings}
\tikzset{
place/.style={
circle,
thick,
draw=black!75,
%fill=white!20,
minimum size=6mm,
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
},
markedge/.style={
decoration={ markings,
mark=at position .5 with {\draw[-,thick] (-2mm,2mm) -- (2mm,-2mm)node[inner sep=1pt,pos=0.5,auto]{#1};} %% adjust 2mm etc as you wish
},
postaction={decorate}
},
}
\begin{document}
\begin{tikzpicture}[node distance=0.4cm and 1cm,>=stealth',bend angle=45,auto]
\node [transitionV,label=above:$T_1$] (t1) {};
\node [place,tokens=1,label=above:$P_2$] (p2) [right=of t1] {}
edge[pre,markedge={2}] (t1);
\end{tikzpicture}
\end{document}