7

I have one automata FSA as below.

I wish to customize the start arrow with a big dot, and keep the arrow 2pt to the target.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,automata}
\def\dx{1cm} \def\dy{1.5cm}
\tikzstyle{state}=[draw,ellipse]
\newcommand{\newState}[4]{\node[state,#3](#1)[#4]{#2};}
\newcommand{\newTransition}[4]{\path[->] (#1) edge [#4] node {#3} (#2);} 
\begin{document}
\begin{tikzpicture}[node distance=\dy and \dx,
  >=latex,shorten >=2pt,shorten <=2pt,auto,
  semithick  %semithick, thick, thin semithick
  ]
  \newState{S}{$SS$}{initial below,initial text={}}{}
  \newState{q1}{$QQ1$}{right=of S}{}
  \newState{q2}{$QQ2$}{below=of q1}{}
  \newState{q3}{$QQ3$}{right=of q1}{accepting} 

  \newTransition{S}{q1}{aa}{}
  \newTransition{q1}{q2}{bb}{bend left}
  \newTransition{q2}{q1}{cc}{bend left}
  \newTransition{q1}{q3}{dd}{}
  \draw[<-] (S) -- node[midway,sloped,below,rotate=180] {start} ++(0,-\dy) [fill] circle (4pt);
  \end{tikzpicture}
\end{document}

My question is:

  1. The start arrow didn't keep the 2pt distance from the target.
  2. Is this right way to draw such a big dot?
  3. The start text direction need to be rotate 180,is it right way to do it?

Output:

enter image description here

1 Answer 1

6

Instead of manually drawing the initial arrow, I'd suggest you to use the initial distance key and the every initial by arrow style to customize the appearance. For example, you could use

initial distance=1cm,
every initial by arrow/.style={*->}

A complete example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,automata}

\def\dx{1cm} 
\def\dy{1.5cm}

\tikzset{
  state/.style={draw,ellipse}
}

\newcommand{\newState}[4]{\node[state,#3](#1)[#4]{#2};}
\newcommand{\newTransition}[4]{\path[->] (#1) edge [#4] node {#3} (#2);} 

\begin{document}
\begin{tikzpicture}[node distance=\dy and \dx,
  >=latex,shorten >=2pt,shorten <=2pt,auto,
  semithick,  %semithick, thick, thin semithick
  initial distance=1cm,
  every initial by arrow/.style={*->}
  ]
  \newState{S}{$SS$}{initial below}{}
  \newState{q1}{$QQ1$}{right=of S}{}
  \newState{q2}{$QQ2$}{below=of q1}{}
  \newState{q3}{$QQ3$}{right=of q1}{accepting} 

  \newTransition{S}{q1}{aa}{}
  \newTransition{q1}{q2}{bb}{bend left}
  \newTransition{q2}{q1}{cc}{bend left}
  \newTransition{q1}{q3}{dd}{}
  \end{tikzpicture}
\end{document}

The output:

enter image description here

2
  • Great idea, but how can we draw the init text "start" sloped on the arrow, just as style in my original diagram?
    – Beatlej
    Jan 17, 2015 at 17:31
  • @Beatlej I think that it's better not to rotate the "start" text, but if you want to do it, you'll need to set initial text={} in the tikzpicture and then place the text manually with something like \node[rotate=90,anchor=north east] at (S.south) {start}; Jan 17, 2015 at 17:46

You must log in to answer this question.

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