有人知道如何在自动机的边缘添加多个对象吗?我试过标签,但只能添加一个标签。我需要绘制街头自动机,如下图所示:
答案1
以下是使用装饰的一种可能性:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.markings}
\begin{document}
\begin{tikzpicture}[mysta/.style={circle,draw,minimum size=25pt},
shorten >=1pt,node distance=3cm,on grid,auto]
\node[mysta] (q0) {};
\node[mysta,right=of q0] (q1) {};
\node[mysta,below=of q0] (q2) {};
\node[mysta,right=of q2] (q3) {};
\draw[<-] (q0) -- +(-30pt,0);
\begin{scope}[decoration={
markings,
mark=at position 0.38
with {\node[circle,draw,fill,inner sep=2pt] {};},
mark=at position 0.62
with {\node[circle,draw,fill=white,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) -- node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q0) to[bend left] node[left] {$oc$} (q2);
\draw[postaction=decorate,->] (q1) -- node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q3) to[out=20,in=-20,looseness=8] node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q2) to[out=20,in=-20,looseness=8] node[right] {$oc$} (q2);
\end{scope}
\begin{scope}[decoration={
markings,
mark=at position 0.5
with {\node[circle,draw,fill,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) -- node[above=1pt] {$\top$} (q1);
\draw[postaction=decorate,->] (q1) to[out=20,in=-20,looseness=8] node[right=1pt] {$\top$} (q1);
\end{scope}
\begin{scope}[decoration={
markings,
mark=at position 0.5
with {\node[circle,draw,fill=white,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) to[bend right] node[left=1.5pt] {$\neg co$} (q2);
\draw[postaction=decorate,->] (q2) to[out=200,in=160,looseness=8] node[left=1.5pt] {$\neg co$} (q2);
\end{scope}
\end{tikzpicture}
\end{document}
在上述解决方案中,对于具有两个装饰(黑色填充圆圈和白色填充圆圈)的路径,两个装饰之间的距离不是恒定的(例如,比较对角线路径中两个圆圈之间的距离与直线向下路径中的圆圈之间的距离)。为了纠正这个问题,在下面的例子中,我使用了\pgfdecoratedpathlength
由皮奥特·维德里奇在his answer
到如何在路径上定位多个装饰并保持它们的分离不变?:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.markings}
\begin{document}
\begin{tikzpicture}[mysta/.style={circle,draw,minimum size=25pt},
shorten >=1pt,node distance=3cm,on grid,auto]
\node[mysta] (q0) {};
\node[mysta,right=of q0] (q1) {};
\node[mysta,below=of q0] (q2) {};
\node[mysta,right=of q2] (q3) {};
\draw[<-] (q0) -- +(-30pt,0);
\begin{scope}[decoration={
markings,
mark=at position 0.5*\pgfdecoratedpathlength-6pt
with {\node[circle,draw,fill,inner sep=2pt] {};},
mark=at position 0.5*\pgfdecoratedpathlength+6pt
with {\node[circle,draw,fill=white,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) -- node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q0) to[bend left] node[left] {$oc$} (q2);
\draw[postaction=decorate,->] (q1) -- node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q3) to[out=20,in=-20,looseness=8] node[right] {$\neg en$} (q3);
\draw[postaction=decorate,->] (q2) to[out=20,in=-20,looseness=8] node[right] {$oc$} (q2);
\end{scope}
\begin{scope}[decoration={
markings,
mark=at position 0.5
with {\node[circle,draw,fill,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) -- node[above=1pt] {$\top$} (q1);
\draw[postaction=decorate,->] (q1) to[out=20,in=-20,looseness=8] node[right=1pt] {$\top$} (q1);
\end{scope}
\begin{scope}[decoration={
markings,
mark=at position 0.5
with {\node[circle,draw,fill=white,inner sep=2pt] {};}
}
]
\draw[postaction=decorate,->] (q0) to[bend right] node[left=1.5pt] {$\neg co$} (q2);
\draw[postaction=decorate,->] (q2) to[out=200,in=160,looseness=8] node[left=1.5pt] {$\neg co$} (q2);
\end{scope}
\end{tikzpicture}
\end{document}