2

I am currently drawing some state diagrams of automata in Latex using the tikz library and I'm currently struggling to customize my starting arrows. The default starting arrow, while clear, isn't what I want. I want to be able to use basically a large greater than sign (>) to indicate the initial node instead of an arrow. I know there's some way to do it because my text book (Languages and Machines, Sudkamp 3rd edition) has these beautiful latex drawings with this exact feature:

enter image description here

which is comparable to my drawing but without the same starting arrow:

enter image description here

I can recognize that he probably changed the arrowheads for the loops with some variant of >=latex, but I am at a loss as to how one would customize the initial arrow like he did. Is there some easy way customize the starting arrow like this with tikz, especially with tikzset so that it wouldn't have to be redone in every drawing? My code (to produce second image) is currently

\documentclass[12pt]{article}

\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{tikz}
\usepackage{mathtools}
\usetikzlibrary{automata,positioning,arrows,calc}

% (failed attempts to replicate Sudkamp's arrow commented out below)
%\tikzset{initial text={}}
%\tikzset{initial distance=0.01cm}

\begin{document}

  \begin{center}
    \begin{tikzpicture}[shorten >=1pt, node distance=3cm,auto,]
      \node[state,initial] (q0) {$q_0$};
      \node[state] (q1) [right of=q0] {$q_1$};
      \node[state,accepting] (q2) [below of=q1] {$q_2$};
      \path[->] (q0) edge [loop above] node {a} ()
                (q0) edge node {b} (q1)
                (q1) edge node {a} (q2)
                (q1) edge [loop above] node {b} (q1)
                (q2) edge [loop right] node {a} ()
                (q2) edge node {b} (q0);
     \end{tikzpicture}
     \end{center}
   \end{document}
2

Let me know if this is what you want (I'm not sure to have understood well your question).

I've searched a bit in the tikz manual, and the arrow tip closest to the first one of your first picture seems the Classical TikZ Rightarrow.

If you want the other arrows like the ones in your first picture, use -Stealth.

arrows is deprecated, use arrows.meta, instead.

\documentclass[12pt]{article}

\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{mathtools, amssymb}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows.meta,calc,decorations.markings}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt, node distance=3cm,auto,]
        \node[state] (q0) {$q_0$};
        \path[decoration={markings,mark=at position 1 with \arrow{Classical TikZ Rightarrow[length=2mm]}}, decorate] (q0.west);
        \node[state] (q1) [right of=q0] {$q_1$};
        \node[state,accepting] (q2) [below of=q1] {$q_2$};
        \path[->] (q0) edge [loop above] node {a} ()
        (q0) edge node {b} (q1)
        (q1) edge node {a} (q2)
        (q1) edge [loop above] node {b} (q1)
        (q2) edge [loop right] node {a} ()
        (q2) edge node {b} (q0);
        \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

Otherwise, draw two simple lines, I've also used the Stealth tip here, to show you the difference:

\documentclass[12pt]{article}

\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{mathtools, amssymb}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows.meta}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt, node distance=3cm,auto]
        \node[state] (q0) {$q_0$};
        \draw (q0.west) -- ++(-2mm,2mm);
        \draw (q0.west) -- ++(-2mm,-2mm);
        \node[state] (q1) [right of=q0] {$q_1$};
        \node[state,accepting] (q2) [below of=q1] {$q_2$};
        \path[-Stealth] (q0) edge [loop above, >=Stealth] node {a} ()
        (q0) edge node {b} (q1)
        (q1) edge node {a} (q2)
        (q1) edge [loop above, >=Stealth] node {b} (q1)
        (q2) edge [loop right, >=Stealth] node {a} ()
        (q2) edge node {b} (q0);
        \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

P.S. = Zarko reminded me that mathtools already loads amsmath, I've removed the latter from my MWEs.

  • Perfect solution, looking at textbook I'm 99% certain this what the author did, adjusted all of them to 3mm and it looks exactly like it. Thanks! – Adam Camilli Sep 17 '17 at 21:50
  • @AdamCamilli You're welcome, thank you for accepting my answer! – CarLaTeX Sep 18 '17 at 3:03
2

how about simple use of symbol $>$?

\documentclass[12pt]{article}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{mathtools, amssymb}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[auto,
            shorten > = 1pt, 
        node distance = 3cm and 3cm]
        \node[state] (q0) {$q_0$};
        \node[inner sep=0pt,outer sep=-1pt,left=0pt of q0.west]{$>$};
        \node[state] (q1) [right of=q0] {$q_1$};
        \node[state,accepting] (q2) [below of=q1] {$q_2$};
        \path[->] (q0) edge [loop above] node {a} ()
        (q0) edge ["b"] (q1)
        (q1) edge ["a"] (q2)
        (q1) edge [loop above, "b"] (q1)
        (q2) edge [loop right, "a"] ()
        (q2) edge ["b"] (q0);
        \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

off-topic: \mathtools supersedes amsmath, so it is sufficient to load only mathtools.

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.