我正在使用 tikz 绘制自动机,但不幸的是我遇到了一些问题。到目前为止,它看起来像这样: 。
我不喜欢的是
- 两个转换描述非常接近(我更希望 (0,0,1) 位于从 q_0 到 q_X 的转换的另一侧)
-q_0 应该是一个接受状态,但是我们看不到它
如能得到任何帮助都将不胜感激,提前致谢!
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{mathtools}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{ amssymb }
\newcommand{\tvect}[3]{%
\ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}} %(für kleinere Matrix)
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\tikzstyle{every state}=[fill=blue!60,draw=none,text=white]
\node[state,initial,accepting] (0) {$q_0$};
\node[state] (X) [below right of=0] {$q_X$};
\node[state] (1) [above right of=X] {$q_1$};
\path
(0) edge [loop above] node {\tvect{0}{1}{1}} (0)
edge [bend left] node {\tvect{1}{1}{0}} (1)
edge node {\tvect{0}{0}{1}} (X)
(1) edge node {$\tvect{\square}{0}{1}$} (0)
edge node {\tvect{1}{0}{1}} (X)
;
\end{tikzpicture}
\end{document}
答案1
像这样吗?
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{mathtools}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{ amssymb }
\newcommand{\tvect}[3]{%
\ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}} %(für kleinere Matrix)
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\tikzstyle{every state}=[fill=blue!60,draw=none,text=white]
\node[state,initial,accepting] (0) {$q_0$};
\node[state] (X) [below right of=0] {$q_X$};
\node[state] (1) [above right of=X] {$q_1$};
\path
(0) edge [loop above] node {\tvect{0}{1}{1}} (0)
edge [bend left=50] node {\tvect{1}{1}{0}} (1)
edge node[left=3pt,pos=0.7] {\tvect{0}{0}{1}} (X)
(1) edge node[above] {$\tvect{\square}{0}{1}$} (0)
edge node[right=3pt,pos=0.7] {\tvect{1}{0}{1}} (X)
;
\end{tikzpicture}
\end{document}
答案2
边缘标签(引号)的定位略有不同,使用方式positioning
和quotes
库如下:
%\documentclass{article}
\documentclass[border=3mm]{standalone}
\usepackage{amssymb, mathtools}
\newcommand\psm[1]{$\begin{psmallmatrix}#1\end{psmallmatrix}$}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
automata,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[auto,
node distance = 15mm,
every state/.style = {fill=blue!60,text=white,
minimum size=2em, inner sep=1pt, outer sep=1pt},
> = Stealth,
every edge/.style = {draw, ->}
]
% state nodes
\node (q0) [state, accepting] {$q_0$};
\node (qx) [state, below right=of q0] {$q_X$};
\node (q1) [state, above right=of qx] {$q_1$};
% connections
\path
(q0) edge [loop above, "\psm{0\\1\\1}"] (q0)
edge [bend left, "\psm{1\\1\\0}"] (q1)
(q1) edge ["\psm{\square\\0\\1}"] (q0)
(q0) edge ["\psm{0\\0\\1}" '] (qx)
(q1) edge ["\psm{0\\0\\1}"] (qx);
\end{tikzpicture}
\end{document}
编辑:更正q0
状态:似乎只应接受首and not
字母,现在已删除。and
, so option
笔记:accepting
状态与 的区别initial
仅在于缺少带标签的输入箭头start
。两者都有双线形边框。