我正在使用以下代码:
\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}
但我希望所有箭头都是双向的。我该怎么做?谢谢。
答案1
我们只需要调整三种样式:
- 路径绘制的风格
\draw
; edge
s绘画的风格\draw
;loop
边缘绘制的风格\draw
。
我们可以附加<->
到\draw
命令并使用.append style
对样式执行相同的操作every loop
:every edge
\draw[
>=latex,
auto=right,
loop above/.style={out=75,in=105,loop},
every loop/.append style={<->},
every edge/.append style={<->},
<->
]
...
完整代码:
\documentclass[tikz,border=10pt,multi]{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,
auto=right,
loop above/.style={out=75,in=105,loop},
every loop/.append style={<->},
every edge/.append style={<->},
<->
]
(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}