3

This is my code

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{arrows,positioning,automata}
\PassOptionsToPackage{usernames,dvipsnames,svgnames}{xcolor}

\begin{document}

\begin{tikzpicture}
[>=stealth',shorten >=1pt,node distance=3cm,on grid,initial/.style    ={}]
  \node[state]          (a)                         {$3$};
  \node[state]          (b) [right =of a]           {$4$};
  \node[state]          (c) [above =of b]           {$2$};
  \node[state]          (d) [above =of a]           {$1$};
\tikzset{mystyle/.style={->,double=green}} 
\tikzset{every node/.style={fill=white}} 
\path (a)     edge [mystyle]    node   {$5$} (b)
      (a)     edge [mystyle]    node   {$3$} (c) 
      (b)     edge [mystyle]    node   {$4$} (c)
      (b)     edge [mystyle]    node   {$2$} (d)
      (d)     edge [mystyle]    node   {$1$} (a);
\end{tikzpicture}

\end{document}

This gives me this picture

enter image description here

How do i change my code such that the numbering of edge 2 and edge 3 don't coincide anymore?

1
3

Use the pos= option on the arrow labels in the following way:

\path (a)     edge [mystyle]    node   {$5$} (b)
      (a)     edge [mystyle,pos=.3]    node   {$3$} (c) 
      (b)     edge [mystyle]    node   {$4$} (c)
      (b)     edge [mystyle,pos=.3]    node   {$2$} (d)
      (d)     edge [mystyle]    node   {$1$} (a);

The position can be adjusted as necessary, from 0 to 1.

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.