我有以下 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}
我想改变状态节点的大小,以便我可以容纳类似This is \\ the initial \\ state
里面的东西q_0
(而不是q_0
)。
我还想使循环适当地变宽以适应更大的状态(如果它不能自动扩展的话)。
答案1
您可以添加align=center
到\node
选项中。循环将自动调整。如果您想调整节点中的字体大小,请添加font=\small
(或您喜欢的任何大小)。
\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}
答案2
不要将\scriptsize
尺寸增加太多。
\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}