I'm trying to add text captions on edges but I can't make it work.

\begin{tikzpicture}[shorten >=1pt,-]

\tikzstyle{vertex}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]                   
\foreach \name/\angle/\text in {P-0/234/0, P-1/162/1, 
                                P-2/90/2, P-3/18/3, P-4/-54/4}
  \node[vertex,xshift=6cm,yshift=.5cm] (\name) at (\angle:1.5cm) {$\text$};

\foreach \from/\to in {0/4, 4/1,1/2,2/4,0/3}
  \draw (P-\from) -- (P-\to);

Could someone help me? Thanks!

  • What do you want on the edge? – Leo Liu Jan 7 '11 at 12:44
  • For example text: "e_1" and so on – Martin Vseticka Jan 7 '11 at 12:48
  • It's good that you mark your code block. It's even better if you indent by just 4 spaces (and use only a bit of further indentation). – Hendrik Vogt Jan 7 '11 at 12:58
  • @Hendrik: I had the code indented with more spaces and I was looking for a way how to "unintend" the block of text when asking the question? Or do I need to do that in an external text editor? – Martin Vseticka Jan 7 '11 at 13:14
  • You had a lot of tab stops in it. The best way is to insert the code without any extra indentation (and without any tab stops); then highlight the code and click the "code" button (with "101010" on it). – Hendrik Vogt Jan 7 '11 at 13:30

For example, \draw (P-\from) -- node {\from\ to \to} (P-\to); And you can use more options to change the style:

\draw (P-\from) -- node[auto,sloped,font=\footnotesize] {\from\ to \to} (P-\to);

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.