
tikz でステート マシン ダイアグラムを作成しているときに、中心からずれているように見えることに気付きました。この結果は、すべてのノードが同じ半径を持ち、角度が異なる foreach 構造を使用してダイアグラムが作成された方法のため、直感に反しているように思えます。また、座標 (0,0) に 1 つのノードを配置しましたが、中心に配置されていないようです。以下に、この問題を示す実際の例を示します。何らかの理由で私が見逃している論理的な説明があるはずです。おそらく、ここで何が起こっているのか説明できる人がいるでしょう。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{cmbright}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,positioning,calc}
\begin{document}
Indented text
\noindent Unindented text
\begin{figure}[h]
\centering
\begin{tikzpicture}[-Stealth,shorten >=1pt,semithick]
\tikzstyle{every state}=[fill=blue!20,draw=blue!50,very thick,text=black,minimum size=1cm]
\def \n {8}
\def \radius {6cm}
\node[state] (c) at (0,0) {};
\foreach \s/\stext in {1/1,2/2\_1,3/3,4/4,5/5,6/6,7/7,8/8}
{
\node[state] (\s) at ({-360/\n * (\s - 1)+90}:\radius) {\stext};
}
\end{tikzpicture}
\end{figure}
\end{document}
答え1
コードをコンパイルすると、次の警告が表示されます。これは、画像がテキスト幅よりも広いため、余白に対して中央に配置されていないことを意味します。画像を小さくするには、にオプションOverfull \hbox (26.08575pt too wide)
を追加します。scale=0.9
\begin{tikzpicture}
前者は非推奨となっているため、\tikzstyle
コマンドを に 置き換える必要もあります。\tikzset{every state/.append style={fill=blue!20,draw=blue!50,very thick,text=black,minimum size=1cm}}