TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 using tikz and pgf to draw state machines in a document, and I'd like to be able to have a multiline edge label between two nodes. Something like the following would be ideal:

\begin{tikzpicture}[node distance=2.5cm,auto]
    \node[state] (one) {$q_1$};
    \node[state] (two) [right of=one] {$q_2$};
    \path[->] (one) edge node {$line1 \\ line2$} (two);

However, the typesetting of that fails with the message "There's no line here to end." (Adding additional mathmode markers before and after the line break changes the error message to the vaguer "Something's wrong--perhaps a missing \item.")

Is there a way to break the label in this graph into two lines?

share|improve this question
up vote 14 down vote accepted

I don't think you can break math lines like that. But you can break text lines if you specify an alignment for the text in the node:

\begin{tikzpicture}[node distance=2.5cm,auto]
    \node[state] (one) {$q_1$};
    \node[state] (two) [right of=one] {$q_2$};
    \path[->] (one) edge node[align=center] {$line1$\\$line2$} (two);

(You need an up-to-date version of tikz for this.)

share|improve this answer
Worked great, thanks! – Tim Jan 5 '11 at 3:09
It worked for me too, thanks. Just a side note: if you don't specify ...[align=center] (or left, or right) it doesn't work (at least in my case) – FSp Mar 30 '15 at 10:44

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.