TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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
up vote 4 down vote accepted

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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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