我正在尝试绘制一个状态机,其中一些状态与一个应用程序相关联,而另一个状态与另一个应用程序相关联。我想在我的 tikz 绘图中使用不同的颜色进行说明,但似乎无法使其工作。
\documentclass[11pt,twoside]{article}
% ------- Enable UTF8 characters ------- %
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,shadows.blur,positioning,calc,arrows.meta,automata}
\usetikzlibrary{matrix,calc,decorations.pathreplacing}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\tikzstyle{every state}=[fill=black,draw=none,text=white]
\tikzstyle{every sub}=[fill=red,draw=none,text=white]
\node[state] (A) {State i};
\node (middle) [right = 1.5 cm of A] {h};
\node[state] (B) [right = 3 cm of A] {State j};
\node[sub] (i_1) [above = 1cm of middle ] {$i_1$};
\path (A) edge [bend left] node {$P_{ij}$} (B)
(B) edge [bend left] node {$P_{ji}$} (A)
(A) edge [loop above] node {$P_{ii}$} (A)
(B) edge [loop above] node {$P_{jj}$} (B);
\end{tikzpicture}
\end{figure}
\end{document}
我认为可行的方法是添加本地
\tikzstyle{every sub}=[fill=red,draw=none,text=white]
当我想绘制与其他应用程序相关的状态时可以使用它,但 tikz 似乎不喜欢它,为什么呢?
答案1
像这样?
\documentclass[11pt,twoside]{article}
% ------- Enable UTF8 characters ------- %
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}
\usepackage[floats,active,tightpage]{preview}
\setlength\PreviewBorder{1em}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[auto,
node distance = 12mm and 12mm,
shorten > = 1pt,
> = Stealth,
semithick,
state/.style = {circle, fill=#1, draw=none,
inner sep=1mm, text=white},
state/.default = black
]
\node (A) [state] {State i};
\node (M) [right=of A] {h};
\node (B) [state, right=of M] {State j};
\node (I) [state=red,above=of M]{$i_1$};
%
\path[->] (A) edge [bend left, "$P_{ij}$"] (B)
(B) edge [bend left, "$P_{ji}$"] (A)
(A) edge [loop above, "$P_{ii}$"] (A)
(B) edge [loop above, "$P_{jj}$"] (B);
\end{tikzpicture}
\end{figure}
\end{document}
在姆韦我仅保留了与此图片相关的库。注意:\tikstyle
是贬值的tikz
语法。相反,它使用\tikzset{...} or define
tikzpicture` 元素样式作为其选项,就像在姆韦多于。