3

While creating a state machine diagram with tikz I noticed that it appears to be off center. This result seems counter intuitive to me because of the way the diagram was created, using a foreach construct with all nodes having the same radius and varying angles. I also placed a single node at the coordinate (0,0), but it appears not to be centered. I provide below a working example showing the issue. I am sure there must be a logical explanation that I am missing somehow, and perhaps someone here will be able to explain what's going on

\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}

enter image description here

  • 1
    Welcome to TeX.SE! Please add a screenshot of your result to your question. – Kurt Mar 19 at 21:19
  • 3
    If I compile your code, I recieve the following warning: Overfull \hbox (26.08575pt too wide) which means that yor image is wider than the textwidth and therefor appears to not be centered with respect to the margins. To make the image smaller you could add the scale=0.9 option to \begin{tikzpicture}. – leandriis Mar 19 at 21:21
  • 2
    \tikzstyle is deprecated, please use \tikzset{every state/.append style={fill=blue!20,draw=blue!50,very thick,text=black,minimum size=1cm}} instead. – marmot Mar 19 at 21:59
  • 1
    @marmot Thanks, I copied an modified an example I found (I can't remember where) that might have been for an older version – jorges Mar 19 at 23:19
  • 1
    @leandriis Would you like to add an answer? – CarLaTeX Mar 20 at 6:08
3

If I compile your code, I recieve the following warning: Overfull \hbox (26.08575pt too wide) which means that yor image is wider than the textwidth and therefor appears to not be centered with respect to the margins. To make the image smaller you could add the scale=0.9 option to \begin{tikzpicture}.

You should also replace the \tikzstyle command by \tikzset{every state/.append style={fill=blue!20,draw=blue!50,very thick,text=black,minimum size=1cm}} as the former is deprecated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.