1

How can I place the loop of vertex {q_1, q_2, q_3} and vertex {empty set} above and below these vertices, respectively (as in the drawing below), instead of on the right?

enter image description here

This is my .TEX:

\documentclass[tikz,12pt,border=1mm]{standalone}
\usetikzlibrary{automata}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[
->, >=stealth,
node distance=3cm,
every state/.style={thick, fill=gray!10},
initial text={$I$},
]
\node[state, initial](Q1) at (0,0) {$\{q_1\}$};
\node[state,accepting] (Q3) at (6,0) {$\{q_4\}$};
\node[state] (V) at (0,-3) {$\varnothing$};
\node[xscale=2, transform shape,state] (Q2) at (3,0) {%
    \scalebox{0.5}[1]{$\{q_1,q_2,q_3\}$}};

\draw (Q1) edge [above] node {$a$} (Q2);
\draw (Q1) edge [left] node {$b,c$} (V);
\draw (Q2) edge [above] node {$b,c$} (Q3);
\draw (Q3) edge [below] node [pos = 0.44,below = 0.2] {$a,b,c$} (V);
\draw (V.20) .. controls +(40:3mm) and +(90:2mm) .. ([xshift=3.5mm] V.east)
node[right] {$a,b,c$} .. controls +(-90:2mm) and +(-40:3mm) .. (V.-20);
\draw (Q2.20) .. controls +(40:3mm) and +(90:2mm) .. ([xshift=3.5mm] Q2.east)
node[right] {$a$} .. controls +(-90:2mm) and +(-40:3mm) .. (Q2.-20);
\end{tikzpicture}
\end{document}

Output:

enter image description here

1
  • 2
    You need to read about Bézier control points (or practice a few minutes in Gimp or Photoshop or...) then change the control points given after the controls keyword. +(40:3mm) is a relative polar coordinate: 40 degrees counter-clockwise from the ((0,0), (0,1)) “vector”, 3mm of radius (counted from the last point placed so far on the path). You also need to change the anchors saying where the small loops start from and end at: (Q2.20) is an anchor located on the border of node (Q2) at polar angle 20 degrees.
    – frougon
    Commented Jun 9, 2022 at 20:23

3 Answers 3

1

As commented by @frougon. This is a way to do it:

\documentclass[tikz,12pt,border=1mm]{standalone}
\usetikzlibrary{automata}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[
->, >=stealth,
node distance=3cm,
every state/.style={thick, fill=gray!10},
initial text={$I$},
]
\node[state, initial](Q1) at (0,0) {$\{q_1\}$};
\node[state,accepting] (Q3) at (6,0) {$\{q_4\}$};
\node[state] (V) at (0,-3) {$\varnothing$};
\node[xscale=2, transform shape,state] (Q2) at (3,0) {%
    \scalebox{0.5}[1]{$\{q_1,q_2,q_3\}$}};

\draw (Q1) edge [above] node {$a$} (Q2);
\draw (Q1) edge [left] node {$b,c$} (V);
\draw (Q2) edge [above] node {$a$} (Q3);
\draw (Q3) edge [below] node [pos = 0.44,below = 0.2] {$a,b,c$} (V);
\draw (V.-115) .. controls +(-130:3mm) and +(180:2mm) .. ([yshift=-3.5mm] V.south)
node[below] {$a,b,c$} .. controls +(0:2mm) and +(-50:3mm) .. (V.-65);
\draw (Q2.100) .. controls +(130:3mm) and +(180:2mm) .. ([yshift=3.5mm] Q2.north)
node[above] {$b,c$} .. controls +(0:2mm) and +(50:3mm) .. (Q2.80);
\end{tikzpicture}
\end{document}

enter image description here

1

Your code is overly complicated. Just \draw from (V) to (V) and set in= and out= angles, together with looseness.

\draw (V)to[out=250, in=290, looseness=3]node[below] {$a,b,c$}(V);
\draw (Q2)to[out=110, in=70, looseness=2]node[above] {$b,c$}(Q2);

enter image description here

1

Based on my answer on the your previous question:

\documentclass[tikz,12pt,border=1mm]{standalone}
\usetikzlibrary{arrows.meta, automata,
                positioning,
                quotes,
                shapes}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[
                 > = Stealth,
     node distance = 11mm and 7mm,
 every edge/.style = {draw, ->},
every state/.style = {ellipse, draw, thick, fill=gray!15,
                      minimum size=2em, inner xsep=0pt},
      initial text = {$I$},
                    ]
\node (Q1)  [state, initial]        {$\{q_1\}$};
\node (Q2)  [state, right=of Q1]    {$\{q_1, q_2, q_3\}$};
\node (Q3)  [state, accepting,
             right=of Q2]           {$\{q_1\}$};
\node (Q4)  [state, below=of Q1]    {$\varnothing$};
\draw   (Q1) edge ["$a$"] (Q2)
        (Q2) edge [loop above, distance=7mm,"$a$"] (Q2)
        (Q2) edge ["$a$"]       (Q3)
        (Q1) edge ["${b,c}$"]   (Q4)
        (Q3) edge ["${a,b,c}$"] (Q4)
        (Q4) edge [loop left, distance=7mm,
                    "${a,b,c}$"] (Q4);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .