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 want to break the input of a path in order to draw Pushdown Automaton,so I try to use the break line symbol \\ and even $$ $$, it still doesnt break the lines. enter image description here
For example, the input should be
0, 1, 2
3, 4, 5

Any idea? Thank you.

Code Sample:

\documentclass[10pt,letterpaper]{article}
\usepackage[latin1]{inputenc}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}

\textbf{PDA:}\\
    \begin{tikzpicture}[shorten >=1pt,node distance=5cm,on grid,auto] 
        \node[state,initial]    (q_0)                   {$q_0$}; 
        \node[state,accepting]  (q_1)   [right=of q_0]  {$q_1$}; 
        \node[state]            (q_2)   [right=of q_1]  {$q_2$}; 
        \node[state]            (q_3)   [below=of q_1]  {$q_3$};

        \path[->]
        (q_0)   edge                    node {0,1}            (q_1)
                edge    [loop above]    node {0,1,2,3,4,5}            (q_0)

        (q_1)   edge                    node {0,1}            (q_2)

        (q_2)   edge    [loop right]    node {1}              (q_2)  

        ; %end path 
    \end{tikzpicture}
\\
\end{document}  
share|improve this question

3 Answers 3

up vote 29 down vote accepted

One simple method is to specify text characteristics within the node : text width, etc. This will let you do exactly what you want, without any extra package. For example,

\documentclass[]{minimal}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=5cm,on grid,auto] 

\node[state,initial] (q_0) {$q_0$}; 
\path[->] (q_0) edge[loop above] node[text width=1cm,align=center] {0,1,2\\3,4,5} (q_0); 

\end{tikzpicture}
\end{document}  

The result is

enter image description here

share|improve this answer
    
Very nice! Thank you. In fact, I was playing around with text-width but haven't figured out its rule. –  Chan Jul 28 '11 at 22:45
4  
You don't need to specify the text width, it's enough to only specify the alignment to get the same output. –  Jake Jul 28 '11 at 23:06
    
@Jake: Thank you. Could you explain how does the alignment take effect on the line break symbols '\\'? –  Chan Jul 29 '11 at 1:40
4  
@Chan: The alignment options are explained starting on page 180 of the pgfmanual. align=center centers the text, align=left aligns it to the left, and so on. Is that what you meant? –  Jake Jul 29 '11 at 1:45
    
@Jake: I guess so ;). Thanks for the reference. –  Chan Jul 29 '11 at 5:04

Based on Frédérics answer and Chans comment you can just do:

\documentclass[]{minimal}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=5cm,on grid,auto] 

\node[state,initial] (q_0) {$q_0$}; 
\path[->] (q_0) edge[loop above] node[align=center] {0,1,2\\3,4,5} (q_0); 

\end{tikzpicture}
\end{document}  

You don't need the text width option, just the align

share|improve this answer

You could use the makecell package. As stated in the package documentation, it provides

\makecell[<vertical or/and horizontal alignment>]{<cell text>}

that aids in the creation of (small-scale) multi-lined tabular cell. In that regard, consider the following alteration to your code:

...
\usepackage{makecell}%
...
\path[->]
  (q_0) edge node {0,1} (q_1)
        edge [loop above] node {\makecell[l]{0,1,2,\\3,4,5}} (q_0)
  (q_1) edge node {0,1} (q_2)
  (q_2) edge [loop right] node {1} (q_2)
 ; %end path

Multi-lined node input

share|improve this answer
    
Thanks a lot. It works like a charm ;) –  Chan Jul 28 '11 at 22:42

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.