如何用 tikz 绘制循环

如何用 tikz 绘制循环

我怎样才能绘制循环?我想用 tikz 绘制此图形,但我做不到。在此处输入图片描述

答案1

有很多示例与你正在寻找的非常相似。下面是一个在节点内部命名状态的示例。

带循环的自动机

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,automata}

\begin{document}
    \begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,node distance=3cm,semithick]
         \tikzset{every state/.style={draw=black,text=black}}
        
         \node[state] (0)               {A};
         \node[state] (1)  [right of=0] {B};
        
         \path (0) edge [loop left]  node {a} (0)
                   edge [bend left]  node {a} (1)
               (1) edge [loop right] node {b} (1)
                   edge [bend left]  node {b} (0);
    \end{tikzpicture}
\end{document}

如果您希望您的状态是点,那就这么做吧!

v2

\begin{tikzpicture}[->,>=Stealth,auto,shorten >=1pt,node distance=3cm,semithick]
         \tikzset{
            mystate/.style={fill=black,circle,inner sep=0pt,minimum width=4pt},
            myloopleft/.style={out=-140,in=140,looseness=20},
            myloopright/.style={out=40,in=-40,looseness=20}}
        
         \node[mystate,label={above:A}] (0)               {};
         \node[mystate,label={above:B}] (1)  [right of=0] {};
        
         \path (0) edge [myloopleft]  node {a} (0)
                   edge [bend left]  node {a} (1)
               (1) edge [myloopright] node {b} (1)
                   edge [bend left]  node {b} (0);
    \end{tikzpicture}

相关内容