Reputation: 109
I would like to display many transitions on one loop arrow in latex. The way I'm doing it right now, the 3 lines are displayed one on top of the other. How can I display the three lines on 3 different lines but on the same loop?
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=4cm,
semithick]
\tikzstyle{every state}=[draw=black,text=black]
\node[initial by arrow,state,initial text=] (1) {1};
\node[state] (2) [right of=1] {2};
\node[state] (3) [right of=2] {3};
\node[state, accepting] (4) [right of=3] {4};
\path
(1) edge node {$\epsilon,\epsilon;\#$} (2)
(2) edge [loop above] node {$a,\epsilon; x$} (2)
(2) edge [loop above] node {$b, \epsilon; \epsilon$} (2)
(2) edge [loop above] node {$\$,\epsilon; \epsilon$} (2)
(2) edge node {$\$,\epsilon; \epsilon$} (3)
(3) edge [loop below] node {$b,a; \epsilon $} (3)
(3) edge [loop below] node {$a,\epsilon; \epsilon $} (3)
(3) edge [loop below] node {$\$,\epsilon;\epsilon $} (3)
(3) edge node {$\epsilon,\#;\epsilon$} (4)
;
\end{tikzpicture}
Upvotes: 0
Views: 2249
Reputation: 11557
You cannot break lines manually in a node. But if you specify a sufficiently small text width, line breaks will occur. You can even control it finely with \mbox and \hspace.
In you case, it is very simple. Just add [text width=something_small] in the node
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=4cm,
semithick]
\tikzstyle{every state}=[draw=black,text=black]
\node[initial by arrow,state,initial text=] (1) {1};
\node[state] (2) [right of=1] {2};
\node[state] (3) [right of=2] {3};
\node[state, accepting] (4) [right of=3] {4};
\path
(1) edge node {$b,\epsilon;\#$} (2)
(2) edge [loop above] node[text width=1cm] {$a,\epsilon; x$
$b, \epsilon; \epsilon$} (2)
(2) edge node {$\$,\epsilon; a$} (3)
(3) edge [loop below] node[text width=1cm] {$b,a; \epsilon $
$\$,\epsilon;\epsilon $} (3)
(3) edge node {$\epsilon,\#;\epsilon$} (4)
;
\end{tikzpicture}
\end{document}
Upvotes: 1