我想使用tikz
这个包来创建这个马尔可夫链,但是遇到了很多问题。谁能发布正确的代码来创建以下马尔可夫链?
答案1
图书馆positioning
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}
\node[state] (0) {0};
\node[state,right=of 0] (1) {1};
\node[state,right=of 1] (2) {2};
\coordinate[draw=none,right=of 2] (2-g);
\node[state,right=of {2-g},text depth=0pt] (g) {g};
\draw[
>=latex,
% every node/.style={above,midway},% either
auto=right, % or
loop above/.style={out=75,in=105,loop},
every loop,
]
(g) edge[loop above] node {$p_{gg}$} (g)
edge node {$p_{gg-1}$} (2-g)
(2-g) to node {$p_{32}$} (2)
edge[loop above] node {$p_{22}$} (2)
(2) edge node {$p_{21}$} (1)
(1) edge[loop above] node {$p_{11}$} (1)
edge node {$p_{10}$} (0)
(0) edge[loop above] node {$p_{00}$} (0);
\end{tikzpicture}
\end{document}
输出
\coordinate
用以下代码替换
\node[draw=none,right=of 2] (2-g) {text};
你得到:
图书馆chains
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{automata,chains}
\begin{document}
\begin{tikzpicture}[start chain=going right]
\node[state, on chain] (0) {0};
\node[state, on chain] (1) {1};
\node[state, on chain] (2) {2};
\node[on chain] (2-g) {text};
\node[state, on chain, text depth=0pt] (g) {g};
% The \draw path is like the one above.
\end{tikzpicture}
\end{document}