0

I've started using LaTeX recently, and I'm trying to draw a few partial NFAs for an article; I have little to no experience with TikZ, so forgive me for asking something that is probably trivial.

I'm trying to draw images like these:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

(Those came from here.)

So far I could position the nodes:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \pagestyle{empty}
  Partial NFA example:

  \begin{tikzpicture}[shorten >=1pt,->]
    \tikzstyle{state}=[circle,draw=black,thick]
    \tikzstyle{block}=[rectangle,draw=black,thick,minimum width=25pt]

    \node[state] (s) at (1,1) { };
    \node[block] (e) at (5,2) {\texttt{e}};
    \node[] (x) at (4,0) { };

    \draw (0,0) -- (s); % Start
    \draw (s) edge[bend left=30] (e);
    \draw (e) edge[bend left=30] (s);
    \draw (s) edge[bend right=30] (x);
  \end{tikzpicture}
\end{document}

But I couldn't get even close to what I want. I have no idea how to make the arrows properly.

Could anyone give me some help?

4
  • 2
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Commented Apr 1, 2016 at 6:13
  • Ok, no problem; sorry. I've been able to position the nodes so far but I have no idea how to properly make the arrows. I'll edit to add a MWE. Commented Apr 1, 2016 at 6:20
  • Meh, I've been reading for the past two or three hours and this is the best I got so far... :( - I'll be sure to read the TikZ manual on the next few days. Some tips about the arrows would be welcome for now. Commented Apr 1, 2016 at 6:51
  • 1
    Have you tried the automata library with TikZ? It already includes a style that, for example, draws an arrow pointing into a start node. You will still be able to customize the node styles further to use rectangles, etc., but I would start there.
    – hftf
    Commented Apr 1, 2016 at 12:05

1 Answer 1

3

Not a full answer yet, but this should lead you into the right direction ... For details on how the code works, please have a look at the comments in the code, which only contains minor changes to your provided code.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
    \usetikzlibrary{
        arrows.meta,
    }
\begin{document}
\begin{tikzpicture}

    \tikzstyle{state}=[circle,draw=black,thick]
    \tikzstyle{block}=[rectangle,draw=black,thick,minimum width=25pt]

    \node [state] (s) at (1,1) { };
    \node [block] (e) at (5,2) {\texttt{e}};
    \node []      (x) at (4,0) { };

    \begin{scope}[
        ->,
        shorten >=1pt,
        % draw corners rounded
        rounded corners=2mm,
    ]
        % connect the nodes vertical and horizontal lines (`|-')
        % (if you need to draw first horizontal and then vertical lines
        %  use `-|' instead)
        \draw (0,0) |- (s); % Start
        \draw (s) |- (e);
        \draw (e) |-  (s);
        \draw (s) |- (x);

        \draw [draw=white,{To[black]}-,shorten <=1pt] (e.east) -- +(5pt,0);
    \end{scope}
\end{tikzpicture}
\end{document}

image showing the result of above code

4
  • This should lead me to the right path! Thank you. :) Commented Apr 1, 2016 at 7:19
  • Could you add some tip on how to get the arrowhead on the start of the pictures? I mean, there's an arrowhead there without the arrow line itself. Commented Apr 1, 2016 at 7:21
  • 1
    Hmmm--- \draw (s.west) +(-1pt,0) -- (s.west); works. A bit of an hack, though (the 1pt must match the shorten in the style).
    – Rmano
    Commented Apr 1, 2016 at 7:35
  • 2
    @Rmano, this is a good alternative. I have edited my answer using another approach. Commented Apr 1, 2016 at 7:42

You must log in to answer this question.

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