我的问题是路径标签混合了箭头,我的代码如下:
\documentclass{article}
\usepackage{tikz}
\usepackage[intlimits]{amsmath}
\begin{document}
\begin{center}
\begin{tikzpicture}[->, >=stealth', auto, semithick, node distance=3cm]
\node[state] (x0) {$x_0$};
\node[state] (x3)[above right of=x0] {$x_3$};
\node[state] (x4)[below right of=x0] {$x_4$};
\node[state] (x1)[right of=x3] {$x_1$};
\node[state] (x6)[right of=x4] {$x_6$};
\node[state] (x2)[below right of=x1] {$x_2$};
\node[state] (x5)[below right of=x2] {$x_5$};
\path
(x1) edge[loop above] node{$1/2$} (x1)
edge[ left] node{$1/2$} (x3)
(x0) edge[loop left] node{$1/3$} (x0)
edge[bend left] node{$1/3$} (x3)
edge[bend left] node{$1/3$} (x4)
(x3) edge[loop above] node{$1/2$} (x3)
edge[bend left] node{$1/2$} (x0)
(x2) edge[loop right] node{$1$} (x2)
(x5) edge[loop left] node{$1$} (x5)
(x4) edge[bend left] node{$1/2$} (x0)
edge[bend right] node{$1/2$} (x3)
(x6) edge[ left] node{$1/3$} (x1)
edge[ left] node{$1/3$} (x2)
edge[ right] node{$1/3$} (x4);
\end{tikzpicture}
\end{center}
\end{document}
所以我的问题是如何移动,例如将路径 x3-x1 的标签移动到线的上方?并将路径 x3-x4 的标签移动到线的右侧?
答案1
它们的位置“错误”,因为你声明它们“错误”。因此,你可以更改相应node
s 的定位键,如下所示修订 1我的答案(参见那里的代码中的注释)。
但是由于您使用了auto
键,大多数节点默认位于右侧。如果您认为它们应该位于“另一侧”,只需添加键即可swap
。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{
arrows,
}
\begin{document}
\begin{tikzpicture}[
->,
>=stealth',
auto,
semithick,
node distance=3cm,
state/.style={
circle,
draw,
},
]
\begin{scope}[
every node/.append style={
state,
},
]
\node (x0) {$x_0$};
\node (x3) [above right of=x0] {$x_3$};
\node (x4) [below right of=x0] {$x_4$};
\node (x1) [right of=x3] {$x_1$};
\node (x6) [right of=x4] {$x_6$};
\node (x2) [below right of=x1] {$x_2$};
\node (x5) [below right of=x2] {$x_5$};
\end{scope}
\path
(x1) edge [loop above] node {$1/2$} (x1)
edge node [swap] {$1/2$} (x3)
(x0) edge [loop left] node {$1/3$} (x0)
edge [bend left] node {$1/3$} (x3)
edge [bend left] node {$1/3$} (x4)
(x3) edge [loop above] node {$1/2$} (x3)
edge [bend left] node {$1/2$} (x0)
(x2) edge [loop right] node {$1$} (x2)
(x5) edge [loop left] node {$1$} (x5)
(x4) edge [bend left] node {$1/2$} (x0)
edge [bend right] node {$1/2$} (x3)
(x6) edge node {$1/3$} (x1)
edge node {$1/3$} (x2)
edge node [swap] {$1/3$} (x4);
\end{tikzpicture}
\end{document}