5

In this picture my code draws the red loops. I'd like to replace them with the hand drawn ones in black.

enter image description here

I've tried lots of cargo cult programming with tikz options from changing loop size and shape in tikz , changing loop size and shape in tikz , How to draw bigger circular states and multiple transitions in automata? and other sites, to no avail. Perhaps those interventions may not work properly with the automata library.

(I'd like larger arrowheads, too, thanks.)

MWE:

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
->,  % makes the edges directed
>=stealth', % makes the arrow heads bold
node distance=2.5cm, %  minimum distance between two nodes. Change if necessary.
every state/.style={thick}, % sets the properties for each 'state' node
}
\begin{document}
\begin{tikzpicture}
\node[state] (0) {$0$};
\node[state, right of=0] (1) {$1$};
\node[state, right of=1] (2) {$2$};
\node[state, right of=2] (3) {$3$};
\node[state, right of=3] (4) {$4$};
\node[state, right of=4] (5) {$5$};
% march down
\draw[thick](1) edge[bend right, above] (0);
\draw[thick](2) edge[bend right, above] (1);
\draw[thick](3) edge[bend right, above] (2);
\draw[thick](4) edge[bend right, above] (3);
\draw[thick](5) edge[bend right, above] (4);
% skip dowo
\draw[thick](2) edge[bend right, above] (0);
\draw[thick](3) edge[bend right, above] (1);
\draw[thick](4) edge[bend right, above] (2);
\draw[thick](5) edge[bend right, above] (3);
% march up
\draw[thick](1) edge[bend right, below] (2);
\draw[thick](2) edge[bend right, below] (3);
\draw[thick](3) edge[bend right, below] (4);
\draw[thick](4) edge[bend right, below] (5);
% skip up
\draw[thick](1) edge[bend right, below] (3);
\draw[thick](2) edge[bend right, below] (4);
\draw[thick](3) edge[bend right, below] (5);
% loops
\draw[thick] (1) edge[loop left, red] (1);
\draw[thick] (4) edge[loop right, red] (4);
\draw[thick] (5) edge[loop left, red] (5);
\draw[thick] (5) edge[loop right, red] (5);
\end{tikzpicture}
\end{document}
Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69

3 Answers3

6

Something like this?

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows}

\tikzset{
->,  % makes the edges directed
>=stealth', % makes the arrow heads bold
node distance=2.5cm, %  minimum distance between two nodes. Change if necessary.
every state/.style={thick}, % sets the properties for each 'state' node
}

\begin{document}

\begin{tikzpicture}
\node[state] (0) {$0$};
\node[state, right of=0] (1) {$1$};
\node[state, right of=1] (2) {$2$};
\node[state, right of=2] (3) {$3$};
\node[state, right of=3] (4) {$4$};
\node[state, right of=4] (5) {$5$};
% march down
\draw[thick](1) edge[bend right, above] (0);
\draw[thick](2) edge[bend right, above] (1);
\draw[thick](3) edge[bend right, above] (2);
\draw[thick](4) edge[bend right, above] (3);
\draw[thick](5) edge[bend right, above] (4);
% skip dowo
\draw[thick](2) edge[bend right, above] (0);
\draw[thick](3) edge[bend right, above] (1);
\draw[thick](4) edge[bend right, above] (2);
\draw[thick](5) edge[bend right, above] (3);
% march up
\draw[thick](1) edge[bend right, below] (2);
\draw[thick](2) edge[bend right, below] (3);
\draw[thick](3) edge[bend right, below] (4);
\draw[thick](4) edge[bend right, below] (5);
% skip up
\draw[thick](1) edge[bend right, below] (3);
\draw[thick](2) edge[bend right, below] (4);
\draw[thick](3) edge[bend right, below] (5);
% loops
\draw[thick] (1) edge[loop left, red] (1);
\draw[thick] (4) edge[loop right, red] (4);
\draw[thick] (5) edge[loop left, red] (5);
\draw[thick] (5) edge[loop right, red] (5);
% back loops
\draw[thick] (1) edge[loop right, out=150, in=210, looseness=7] (1);
\draw[thick] (4) edge[loop right, out=330, in=30, looseness=7] (4);
\draw[thick] (5) edge[loop right, out=330, in=30, looseness=7] (5);
\end{tikzpicture}

\end{document}

enter image description here

6

One can always write a style for such things... EDIT: Increased the arrows.

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows.meta}
\tikzset{
->,  % makes the edges directed
>={Stealth[length=3.14mm]}, % makes the arrow heads bold
node distance=2.5cm, %  minimum distance between two nodes. Change if necessary.
every state/.style={thick}, % sets the properties for each 'state' node
my loop left/.style={out=165,in=195,loop},
my loop right/.style={out=-15,in=15,loop}
}
\begin{document}
\begin{tikzpicture}
\node[state] (0) {$0$};
\node[state, right of=0] (1) {$1$};
\node[state, right of=1] (2) {$2$};
\node[state, right of=2] (3) {$3$};
\node[state, right of=3] (4) {$4$};
\node[state, right of=4] (5) {$5$};
% march down
\draw[thick](1) edge[bend right, above] (0);
\draw[thick](2) edge[bend right, above] (1);
\draw[thick](3) edge[bend right, above] (2);
\draw[thick](4) edge[bend right, above] (3);
\draw[thick](5) edge[bend right, above] (4);
% skip dowo
\draw[thick](2) edge[bend right, above] (0);
\draw[thick](3) edge[bend right, above] (1);
\draw[thick](4) edge[bend right, above] (2);
\draw[thick](5) edge[bend right, above] (3);
% march up
\draw[thick](1) edge[bend right, below] (2);
\draw[thick](2) edge[bend right, below] (3);
\draw[thick](3) edge[bend right, below] (4);
\draw[thick](4) edge[bend right, below] (5);
% skip up
\draw[thick](1) edge[bend right, below] (3);
\draw[thick](2) edge[bend right, below] (4);
\draw[thick](3) edge[bend right, below] (5);
% loops
\draw[thick] (1) edge[my loop left, red] (1);
\draw[thick] (4) edge[my loop right, red] (4);
\draw[thick] (5) edge[my loop left, red] (5);
\draw[thick] (5) edge[my loop right, red] (5);
\end{tikzpicture}
\end{document}

enter image description here

And if you would like the loops to become bigger, you can adjust the in and out angles accordingly. Additionally, you may increase looseness, but I am not convinced of the outcome, but that's a matter of taste.

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows.meta}
\tikzset{
->,  % makes the edges directed
>={Stealth[length=3.14mm]}, % makes the arrow heads bold
node distance=2.5cm, %  minimum distance between two nodes. Change if necessary.
every state/.style={thick}, % sets the properties for each 'state' node
my loop left/.style={out=160,in=200,loop},
my loop right/.style={out=-20,in=20,loop}
}
\begin{document}
\begin{tikzpicture}
\node[state] (0) {$0$};
\node[state, right of=0] (1) {$1$};
\node[state, right of=1] (2) {$2$};
\node[state, right of=2] (3) {$3$};
\node[state, right of=3] (4) {$4$};
\node[state, right of=4] (5) {$5$};
% march down
\draw[thick](1) edge[bend right, above] (0);
\draw[thick](2) edge[bend right, above] (1);
\draw[thick](3) edge[bend right, above] (2);
\draw[thick](4) edge[bend right, above] (3);
\draw[thick](5) edge[bend right, above] (4);
% skip dowo
\draw[thick](2) edge[bend right, above] (0);
\draw[thick](3) edge[bend right, above] (1);
\draw[thick](4) edge[bend right, above] (2);
\draw[thick](5) edge[bend right, above] (3);
% march up
\draw[thick](1) edge[bend right, below] (2);
\draw[thick](2) edge[bend right, below] (3);
\draw[thick](3) edge[bend right, below] (4);
\draw[thick](4) edge[bend right, below] (5);
% skip up
\draw[thick](1) edge[bend right, below] (3);
\draw[thick](2) edge[bend right, below] (4);
\draw[thick](3) edge[bend right, below] (5);
% loops
\draw[thick] (1) edge[my loop left, red] (1);
\draw[thick] (4) edge[my loop right, red] (4);
\draw[thick] (5) edge[my loop left, red] (5);
\draw[thick] (5) edge[my loop right, red] (5);
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks for adding the code for bigger arrow heads. I was actually trying to remember it correctly, but couldn’t find it quickly enough. :) – Jasper Habicht Aug 29 '18 at 20:16
  • 1
    @JasperHabicht I think the only thing to remember is that arrows got superseded by arrows.meta. And you can still add it to your nice answer that I upvoted, there is nothing wrong with that. This is a fun site, not competition. –  Aug 29 '18 at 20:34
2

I've accepted @JasperHabicht 's answer, and upvoted @marmot 's. Posting my own here just to show how it all fits together.

enter image description here

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows.meta}
\tikzset{
->,  % makes the edges directed
>={Stealth[length=3.14mm]}, % makes the arrow heads bold and bigger
%>=stealth', % makes the arrow heads bold
node distance=2.5cm, %  minimum distance between two nodes. Change if necessary.
every state/.style={thick}, % sets the properties for each 'state' node
}
\begin{document}
\begin{tikzpicture}
\node[state] (0) {$0$};
\node[state, right of=0] (1) {$1$};
\node[state, right of=1] (2) {$2$};
\node[state, right of=2] (3) {$3$};
\node[state, right of=3] (4) {$4$};
\node[state, right of=4] (5) {$5$};
% march down
\draw[thick](1) edge[bend right, above] (0);
\draw[thick](2) edge[bend right, above] (1);
\draw[thick](3) edge[bend right, above] (2);
\draw[thick](4) edge[bend right, above] (3);
\draw[thick](5) edge[bend right, above] (4);
% skip dowo
\draw[thick](2) edge[bend right, above] (0);
\draw[thick](3) edge[bend right, above] (1);
\draw[thick](4) edge[bend right, above] (2);
\draw[thick](5) edge[bend right, above] (3);
% march up
\draw[thick](1) edge[bend right, below] (2);
\draw[thick](2) edge[bend right, below] (3);
\draw[thick](3) edge[bend right, below] (4);
\draw[thick](4) edge[bend right, below] (5);
% skip up
\draw[thick](1) edge[bend right, below] (3);
\draw[thick](2) edge[bend right, below] (4);
\draw[thick](3) edge[bend right, below] (5);
% loops
\draw[thick] (1) edge[loop right, out=150, in=210, looseness=7] (1);
\draw[thick] (4) edge[loop right, out=330, in=30, looseness=7] (4);
\draw[thick] (5) edge[loop right, out=330, in=30, looseness=7] (5);
\draw[thick] (5) edge[loop right, out=330, in=30, looseness=9] (5);
\end{tikzpicture}
\end{document}
Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69