1

I want to use the TikZ automata library to draw finite automata where the size of the state nodes remains the same regardless of whether the state is accepting or not.

Here's a MWE demonstrating the issue.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}

\tikzstyle{accepting}=[double distance=2pt, outer sep=1pt+\pgflinewidth]

\begin{document}
\begin{tikzpicture}
  \draw[help lines, step=.5cm] (0, 0) grid (4,2);
  \node[state] (q0) at (1,1) {};
  \node[state, accepting] (q1) at (3,1) {};
  \draw (q0) edge [bend left=15, ->] (q1);
\end{tikzpicture}
\end{document}

Two node automata

You can see that the accepting node is larger than the nonaccepting node.

I believe I understand why this is happening: double distance turns on double which causes TikZ to draw two circles with different colors and different widths, first in black with width 2pt+2\pgflinewidth and then in white with width 2pt. This results in the appearance of a double line.

Is there a way that I can modify the style set by accepting such that it reduces the size of the node (or maybe inner sep) appropriately such that the node size doesn't change? Alternatively, can I cause accepting to simply draw a second circle centered on the node?

1 Answer 1

3

After fighting this for days, I found a solution shortly after posting the question, of course.

My solution uses the calc library and path picture.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata, calc}

\tikzstyle{accepting}=[path picture={%
  \draw let 
    \p1 = (path picture bounding box.east),
    \p2 = (path picture bounding box.center)
    in
      (\p2) circle (\x1 - \x2 - 2pt);
  }]

\begin{document}
\begin{tikzpicture}
  \draw[help lines, step=.5cm] (0, 0) grid (4,2);
  \node[state] (q0) at (1,1) {};
  \node[state, accepting] (q1) at (3,1) {};
  \draw (q0) edge [bend left=15, ->] (q1);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .