我是 Tikz 的新手,
读完这个问题后Petri 网中的转换
我想创建这个
这是我的代码,您可以通过此链接访问https://www.writelatex.com/read/bxwwcmmghpmw
\documentclass{article}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri}
\tikzset{
place/.style={
circle,
thick,
draw=blue!75,
fill=blue!20,
minimum size=6mm,
},
transitionH/.style={
rectangle,
thick,
fill=black,
minimum width=8mm,
inner ysep=2pt
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
}
}
\begin{document}
\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]
\node [place,label=above:$P_1$] (p1) {};
\node [transitionV,label=above:$T_1$] (t1) [right of=p1] {}
edge[pre] (p1);
\node [place,tokens=1,label=above:$P_2$] (p2) [right of=t1] {}
edge[pre] (t1);
\node [place,tokens=2,label=above:$P_3$] (p3) [below of=p2] {}
edge[pre] (t1);
\node [transitionV,label=above:$T_2$] (t2) [right of=p3] {}
edge[pre] (p2)
edge[pre] (p3)
edge[post, bend left] (p1);
\node [place,tokens=1, label=above:$P_4$] (p4) [right of=t2] {}
edge[pre] (t2);
\end{tikzpicture}
\end{document}
我对 T2 --> P1 的边缘不太满意,我希望它们垂直居中。
非常感谢您的帮助。
答案1
也许是这样的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning}
\tikzset{
place/.style={
circle,
thick,
draw=blue!75,
fill=blue!20,
minimum size=6mm,
},
transitionH/.style={
rectangle,
thick,
fill=black,
minimum width=8mm,
inner ysep=2pt
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
}
}
\begin{document}
\begin{tikzpicture}[node distance=0.5cm and 1cm,>=stealth',bend angle=45,auto]
\node [place,label=above:$P_1$] (p1) {};
\node [transitionV,label=above:$T_1$] (t1) [right= of p1] {}
edge[pre] (p1);
\node [place,tokens=1,label=above:$P_2$] (p2) [above right=of t1] {}
edge[pre] (t1);
\node [place,tokens=2,label=above:$P_3$] (p3) [below right=of t1] {}
edge[pre] (t1);
\node [transitionV,label=above:$T_2$] (t2) [above right=of p3] {}
edge[pre] (p2)
edge[pre] (p3)
edge[post,out=-110,in=-50,looseness=2,overlay] (p1);
\node [place,tokens=1, label=above:$P_4$] (p4) [above right=of t2] {}
edge[pre] (t2);
\end{tikzpicture}
\end{document}
主要的变化是从过时的语法切换of=
到of=
(使用positioning
库进行相对定位,并使用out=<angle>
、in=<angle>
和 一起looseness
作为边缘(根据您的喜好调整设置)。
另一种选择,这次使用to
路径而不是edge
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning}
\tikzset{
place/.style={
circle,
thick,
draw=blue!75,
fill=blue!20,
minimum size=6mm,
},
transitionH/.style={
rectangle,
thick,
fill=black,
minimum width=8mm,
inner ysep=2pt
},
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 [place,label=above:$P_1$] (p1) {};
\node [transitionV,label=above:$T_1$] (t1) [right= of p1] {}
edge[pre] (p1);
\node [place,tokens=1,label=above:$P_2$] (p2) [above right=of t1] {}
edge[pre] (t1);
\node [place,tokens=2,label=above:$P_3$] (p3) [below right=of t1] {}
edge[pre] (t1);
\node [transitionV,label=above:$T_2$] (t2) [above right=of p3] {}
edge[pre] (p2)
edge[pre] (p3);
\node [place,tokens=1, label=above:$P_4$] (p4) [above right=of t2] {}
edge[pre] (t2);
\draw[post] (t2.east) to[out=-30,in=210,overlay,looseness=2.3] (p1);
\end{tikzpicture}
\end{document}