TikZ,末端没有箭头的自循环

TikZ,末端没有箭头的自循环

在 TikZ 中,在 的上下文中automata,我想绘制一个没有箭头的循环,以便能够突出显示自动机中的路径,如下例所示(突出显示没有任何循环的路径)。对于标准弧(即两个不同状态之间的弧),我只需绘制两个弧:

  • 首先是一条粗彩色圆弧,末端没有任何箭头
  • 第二个标准弧

但这对于循环不起作用。

\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}

答案1

您可以使用单独的样式path来绘制高亮,然后更改every loop该路径的样式以绘制粗彩色线,然后再绘制箭头。我还为高亮线和箭头添加了一些样式。

最小示例:

\documentclass{article}
\usepackage{tikz,siunitx}
\usetikzlibrary{automata,arrows}
\begin{document}

\begin{tikzpicture}[shorten >=1pt,auto,node distance=18mm,semithick,
 highlight/.style={line width=4pt,orange!70},
 MyArrow/.style={->,>=stealth'}]
   \node[initial,initial text= ,initial distance=10mm,state]  (s00)  {$s_{00}$};
   \node[state] (s11) [right of=s00]    {$s_{11}$};
   \path [every loop/.style={highlight}, % draw highlights
             highlight]
     (s11) edge [loop above]  (s11)
     (s00) edge node {$\mathbf{3}$} (s11);
   \path % draw normal paths
     (s00) edge [MyArrow]            node {} (s11)
     (s11) edge [MyArrow,loop above]  node {$3$} (s11);
\end{tikzpicture}
\end{document}

在此处输入图片描述

笔记

不要使用等\bf\it因为它们已被弃用。请改用\bfseries\itshape请参阅\textit我使用或\it\bfseries等有关系吗\bf双字母字体样式命令 ( \bf,\it ...)会在 LaTeX 中复活吗?. 但是对于数学模式,使用\mathbf{...}

相关内容