0

My problem is the path label mixes the arrow, my code is the following:

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

enter image description here

So my question is how to move, for example the label of path x3-x1 above the line? And move the label of path x3-x4 right of the line?

1

They are positioned "wrong" because you stated them "wrong". Thus you could change the positioning keys of the corresponding nodes as in revision 1 of my answer (see the comments in the code there).

But since you use the auto key, most nodes are positioned right by default. And if you thing they should be "on the other side" simply add the swap key.

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

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.