# How do I create transition arrow labels with new lines?

I am using the TikZ package to draw pushdown definite automata. How do I add new lines into the labels of transition arrows?

This does not work:

\begin{tikzpicture}[shorten >=1pt,node distance=3.5cm,on grid,auto]
\node[state, initial, initial where=left, accepting] (A) {A};
\path[->]
(A) edge [loop above] node {$a, b, c$ \\ $c, d, e$ \\ foo \\ bar} (A);
\end{tikzpicture}


Specifically, {$a, b, c$ \\ $c, d, e$ \\ foo \\ bar} ignores the new lines.

-
You could try with the text width parameter of node, namely node [text width=1cm]{...}, although this way it is not possible to explicitly set the line breaks. –  guillem Oct 16 '12 at 7:03
It is also possible to set align=center/left/right/justify to make \ work without setting the width explicitly. –  Tobi Oct 16 '12 at 7:10
As starting point, I think you can refer to How to add newline within node using TikZ? –  Claudio Fiandrino Oct 16 '12 at 7:27

Here is one using the text width option.

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning,automata}

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=3.5cm,on grid,auto]
\node[state, initial, initial where=left, accepting] (A) {A};
\path[->]
(A) edge [loop above,text width=1cm] node {$a, b, c$ \\ $c, d, e$ \\ foo \\ bar} (A);
\end{tikzpicture}
\end{document}


Here is another with the align=left option.

\begin{tikzpicture}[shorten >=1pt,node distance=3.5cm,on grid,auto]
\node[state, initial, initial where=left, accepting] (A) {A};
\path[->]
(A) edge [loop above,align=left] node {$a, b, c$ \\ $c, d, e$ \\ foo \\ bar} (A);
\end{tikzpicture}


Here is with the align=center option.

\begin{tikzpicture}[shorten >=1pt,node distance=3.5cm,on grid,auto]
\node[state, initial, initial where=left, accepting] (A) {A};
\path[->]
(A) edge [loop above,align=center] node {$a, b, c$ \\ $c, d, e$ \\ foo \\ bar} (A);
\end{tikzpicture}


You can even use tables inside the nodes. (But this one's overdoing it already :)

\begin{tikzpicture}[shorten >=1pt,node distance=3.5cm,on grid,auto]
\node[state, initial, initial where=left, accepting] (A) {A};
\path[->]
(A) edge [loop above,text width=2cm] node {
\begin{tabular}{@{}ccc}
$a$,& $b$,& $c$ \\
$c$,& $d$,& $e$ \\
foo & & \\
bar & &
\end{tabular}
} (A);
\end{tikzpicture}


You can see section 16, starting at 179 of the pgf manual for more of this.

-