修复下图?

修复下图?

我设法创建了以下自动机绘图,并且正在尝试修复它以便:

  1. 在状态 0 中,循环不会互相交叉
  2. q_0 和 q_1 之间的 r 和 t 边设置正确(可能有点弯曲,或者其他任何需要让它们不互相交叉的方式)
  3. x、s 相同
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing}
\tikzstyle{every picture}+=[remember picture,inner xsep=0,inner ysep=0.25ex]


\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
   \node[state,initial,accepting] (q_0)   {$q_0$};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
   \node[state,accepting] (q_2) [below=of q_1] {$q_2$};
    \path[->]
    (q_0) edge  [loop above] node {$y$} ()
          edge  node [swap] {$t$} (q_1)
          edge  node [swap] {$s$} (q_2)
          edge  [loop above] node {$s$} ()
    (q_1) edge  [loop above] node {$t$} ()
          edge  node [swap] {$r$} (q_0)
    (q_2) edge  [loop above] node {$r$} ()
          edge  node [swap] {$x$} (q_0);
\end{tikzpicture}

\end{document}

答案1

使用bend left边选项并loop below在节点处进行第二次循环q0

在此处输入图片描述

以及quotes更短代码的库:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}

\begin{document}

\begin{tikzpicture}[
    shorten >=1pt,
    node distance=2cm and 2cm, 
    bend angle=20,
    auto            ]
   \node[state,initial,accepting] (q_0)         {$q_0$};
   \node[state,accepting, right=of q_0] (q_1)   {$q_1$};
   \node[state,accepting, below=of q_1] (q_2)   {$q_2$};
   \path[->]
    (q_0) edge  [loop above,"$y$"] ()
          edge  [bend left,"$t$"] (q_1)
          edge  [bend left,"$s$"] (q_2)
          edge  [loop below,"$s$"] ()
    (q_1) edge  [loop above,"$t$"] ()
          edge  ["$r$"] (q_0)
    (q_2) edge  [loop above,"$r$"] ()
          edge  ["$x$"] (q_0);
\end{tikzpicture}

\end{document}

¸

答案2

这是一种可能的方法,如果您得到其他答案,我不会感到惊讶。

您可以使用sbend left=<angle>作为选项edge来将它们分开。对于循环,您可以修改loosenessin/out角度。请注意,在这种情况下,您需要设置循环的结束节点。

代码输出

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing}
\tikzset{
  every picture/.append style={remember picture,inner xsep=0,inner ysep=0.25ex}
}
\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
   \node[state,initial,accepting] (q_0)   {$q_0$};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
   \node[state,accepting] (q_2) [below=of q_1] {$q_2$};
    \path[->]
    (q_0) edge  [loop above]     node {$y$} ()
         % add bend left=10, remove [swap] from the node
          edge  [bend left=10]   node  {$t$} (q_1)
          edge  [bend left=10]   node  {$s$} (q_2)
          edge  [loop above,
                 % increasing looseness makes the loop bigger
                 looseness=12,
                 % change the start/end angles of the loop
                 out=110, in=70] node {$s$} (q_0) % added q_0 as end node
    (q_1) edge  [loop above]     node {$t$} ()
          edge  [bend left=10]   node {$r$} (q_0)
    (q_2) edge  [loop above]     node {$r$} ()
          edge  [bend left=10]   node {$x$} (q_0);
\end{tikzpicture}
\end{document}

答案3

您可以尝试调整箭头的in和角度:out

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing}
\tikzstyle{every picture}+=[remember picture,inner xsep=0,inner ysep=0.25ex]


\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
   \node[state,initial,accepting] (q_0)   {$q_0$};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
   \node[state,accepting] (q_2) [below=of q_1] {$q_2$};
    \path[->]
    (q_0) edge  [in=120,out=150,loop] node {$y$} ()
          edge  [in=170,out=10] node [above,swap] {$t$} (q_1)
          edge  [in=125,out=-35] node [above,swap] {$s$} (q_2)
          edge  [in=30,out=60,loop] node {$s$} ()
    (q_1) edge  [loop above] node {$t$} ()
          edge  [in=-10,out=-170] node [below,swap] {$r$} (q_0)
    (q_2) edge  [loop above] node {$r$} ()
          edge  [in=-55,out=145] node [below,swap] {$x$} (q_0);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容