在下面的代码中,
\begin{tikzpicture}[node distance=1.5cm,,xscale=2,>=stealth',bend angle=45,auto]
\tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=3mm]
\tikzstyle{red place}=[place,draw=red!75,fill=red!20]
\tikzstyle{transition}=[rectangle,thick,draw=brown!75,
fill=brown!20,minimum size=3mm]
\tikzstyle{every label}=[blue!75]
\begin{scope}
\path
(0, 0) node [place] (p1) {2}
+(-1, 0) node [transition] (t1) {}
edge [post] node[auto,below] {5} (p1)
edge [pre] node[auto,above] {3} (p1);
\end{scope}
\end{tikzpicture}
我得到以下输出:
而我期望的是这样的:
我实际上如何创建一个循环而不是双头箭头?
答案1
您忘记了问题代码中 3.1.4b 手册第 57 页定义的前置和后置样式。
pre/.style={<-,shorten <=1pt,>=stealth',semithick},
post/.style={->,shorten >=1pt,>=stealth',semithick}
我在这些样式中添加了带有和的弯曲bend left
,bend right
因为代码中的两个箭头从同一个节点开始。
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[node distance=1.5cm,,xscale=2,>=stealth',bend angle=45,auto=left,
pre/.style={<-,shorten <=1pt,>=stealth',semithick,bend right},
post/.style={->,shorten >=1pt,>=stealth',semithick,bend left},
place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=3mm},
red place/.style={place,draw=red!75,fill=red!20},
transition/.style={rectangle,thick,draw=brown!75, fill=brown!20,minimum size=3mm},
every label/.style={blue!75}]
\begin{scope}
\path
(0, 0) node [place] (p1) {2}
+(-1, 0) node [transition] (t1) {}
edge [post] node[] {5} (p1)
edge [pre] node[swap] {3} (p1);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
下面的代码绘制了这两个弯曲的箭头。
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[node distance=1.5cm,xscale=2,>=stealth,bend angle=45,auto]
\tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=3mm]
\tikzstyle{red place}=[place,draw=red!75,fill=red!20]
\tikzstyle{transition}=[rectangle,thick,draw=brown!75,
fill=brown!20,minimum size=3mm]
\tikzstyle{every label}=[blue!75]
\tikzset{
state/.style={circle,draw,minimum size=6ex},
arrow/.style={-latex, shorten >=1ex, shorten <=1ex}}
\begin{scope}
\node[place] at (0, 0) (p1) {2};
\node[transition] at (-1, 0) (t1) {2};
\draw [arrow, bend angle=45, bend left] (p1) to (t1) node [auto,below] {3};
\draw [arrow, bend angle=45, bend left] (t1) to (p1) node[auto,above] {5};
\end{scope}
\end{tikzpicture}
\end{document}