6

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.

David Faux
  • 4,117

1 Answers1

6

If you are just adding new lines in the label above the loop, then the answers were already provided in the comments.

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}

enter image description here

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}

enter image description here

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}

enter image description here

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}

enter image description here

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

hpesoj626
  • 17,282