In TikZ, within the context of automata
,
I would like to draw a loop without arrow in order to be able to
highlight a path in an automaton, as shown by the following example
(which highlight a path without any loop).
For standard arc (i.e. arcs between two distinct states) I just
draw two arcs:
- first a thick colored arc without any arrow at its end
- second a standard arc
but this does not work for loops.
\usepackage{color}
\usepackage{tikz} \usetikzlibrary{shapes,arrows,automata,backgrounds,matrix,decorations,trees}
\def\ctrref#1{$\constraint{#1}$\index{#1@$\constraint{#1}$|indexuse}}
\def\ctrrefself#1{$\constraint{#1}$}
\def\argument#1{\mathtt{#1}}
\def\constraint#1{\mathtt{#1}}
\definecolor{MyYellowlight}{cmyk}{0,0,0.05,0}
\begin{figure}[!h]
\begin{center}
{\footnotesize
\begin{tikzpicture}[shorten >=1pt,auto,node distance=18mm,semithick]
\node[initial,initial text= ,initial distance=10mm,state,fill=MyYellowlight] (s00) {$s_{00}$};
\node[state,fill=MyYellowlight] (s11) [right of=s00] {$s_{11}$};
\node[state,fill=MyYellowlight] (s12) [right of=s11] {$s_{12}$};
\node[state,fill=MyYellowlight] (s21) [below of=s12] {$s_{21}$};
\node[state,fill=MyYellowlight] (s31) [below of=s21] {$s_{31}$};
\node[accepting,state,fill=MyYellowlight] (s41) [below of=s31] {$s_{41}$};
\node[accepting,state,fill=MyYellowlight] (s51) [left of=s41] {$s_{51}$};
\node[accepting,state,fill=MyYellowlight] (s61) [left of=s51] {$s_{61}$};
\path
(s00) edge [line width=4pt,orange!70] node {$\bf 3$} (s11)
(s00) edge [->,>=stealth'] node {} (s11)
(s11) edge [line width=4pt,orange!70] node {$\bf 3$} (s12)
(s11) edge [->,>=stealth'] node {} (s12)
(s12) edge [->,>=stealth',loop above] node {$3$} (s12)
(s12) edge [->,>=stealth'] node [left] {$4$} (s21)
(s12) edge [->,>=stealth',bend left] node [right, very near end] {$5$} (s31)
(s12.325) edge [line width=4pt,orange!70,bend left] node {$\bf 6$} (s41)
(s12.325) edge [->,>=stealth', bend left] node {} (s41)
(s21) edge [->,>=stealth'] node [left] {$5$} (s31)
(s21) edge [->,>=stealth',bend right] node [left] {$6$} (s41)
(s31) edge [->,>=stealth'] node [left] {$6$} (s41)
(s41) edge [->,>=stealth',loop right] node {$6$} (s41)
(s41) edge [->,>=stealth'] node [above] {$7$} (s51)
(s41) edge [line width=4pt,orange!70,bend left] node {$\bf 8$} (s61)
(s41) edge [->,>=stealth', bend left] node {} (s61)
(s51) edge [->,>=stealth'] node [above] {$8$} (s61);
\end{tikzpicture}
}
\end{center}
\caption{Automaton of the \ctrrefself{increasing\_global\_cardinality} constraint of the {\bf Example} slot: the path corresponding to the solution $\langle {\color{orange!70}\bold{3}},{\color{orange!70}\bold{3}},{\color{orange!70}\bold{6}},{\color{orange!70}\bold{8}}\rangle$ is depicted by thick orange arcs}
\label{fig:increasing_global_cardinality1}
\end{figure}
Best Answer
You can use a separate
path
to draw the highlight, and change theevery loop
style for that path to draw a thick coloured line, and then draw the arrow afterwards. I also added some styles for the highlight lines and arrows.Minimal example:
Note
Don't use
\bf
,\it
etc. as they are deprecated. use\bfseries
,\itshape
instead, see Does it matter if I use\textit
or\it
,\bfseries
or\bf
, etc. and Will two-letter font style commands (\bf
,\it
, …) ever be resurrected in LaTeX?. For mathmode however, use\mathbf{...}