Take the 2-minute tour ×
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.

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.

share|improve this question
    
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
2  
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

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

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.