2

I have the following FSA:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\tikzstyle{every picture}+=[remember picture,inner xsep=0,inner ysep=0.25ex]

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2.5cm,on grid,auto]
   \node[state,initial,accepting] (q_0)   {$q_0$};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
    \path[->]
    (q_0) edge  node [swap] {b} (q_1)
    (q_1) edge  [loop below] node {d} ();
\end{tikzpicture}

\end{document}

I would like to change the size of the state nodes so I can fit something like This is \\ the initial \\ state inside q_0 (instead of q_0).

I would also like to make the loop wider as appropriately for a larger state (if that doesn't scale automatically).

Alan Munn
  • 218,180
tikzUser
  • 21
  • 1

2 Answers2

2

You can add align=center to the \node options. The loop will adjust automatically. If you want to adjust the fontsize in the node, add font=\small (or any size you like).

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\tikzstyle{every picture}+=[remember picture,inner xsep=0,inner ysep=0.25ex]

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2.5cm,on grid,auto]
   \node[state,initial,accepting,align=center] (q_0)   {This is\\the initial\\state};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
    \path[->]
    (q_0) edge  [loop below] node {b} (q_1)
    (q_0) edge   node [swap] {c} (q_1)
    (q_1) edge  [loop below] node {d} ();
\end{tikzpicture}

\end{document}

output of code

Alan Munn
  • 218,180
  • 1
    Alan, you forgot https://tex.stackexchange.com/questions/52372/should-tikzset-or-tikzstyle-be-used-to-define-tikz-styles :) – CarLaTeX Jan 20 '18 at 05:54
1

With \scriptsize you don't increase the size too much.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{
  automata,
  positioning,
  decorations.text,
  topaths,
  arrows.meta,
  decorations.pathmorphing,
  quotes
}
\tikzset{
  every picture/.append style={remember picture,inner xsep=0,inner ysep=0.25ex},
}

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2.5cm,on grid,auto]
   \node[state,initial,accepting] (q_0)
     {\scriptsize\begin{tabular}{@{}c@{}}This is\\the initial \\ state\end{tabular}};
   \node[state,accepting] (q_1) [right=of q_0] {$q_1$};
   \path[->]
    (q_0) edge  node [swap] {b} (q_1)
    (q_1) edge  [loop below] node {d} ();
\end{tikzpicture}

\end{document}

enter image description here

egreg
  • 1,121,712