9

I am trying to create these:

enter image description here

I have tried to make the first figure with this code

\documentclass[border=10pt]{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows,automata,positioning}

\begin{document}

\begin{tikzpicture}
\node (first) [circle,draw,inner sep=1pt] {};
\node (second) [right=of first] {};
\node (third) [right=of second] {term};
\node (fourth) [right=of third] {};
\node (fifth) [circle,draw,inner sep=1pt,right=of fourth] {};

\node (sixth) [below=of fourth] {};
\node (seventh) [below=of third] {$+$};
\node (eigth) [below=of second] {};

\draw[->] (first) -- (second);
\draw[->] (second) -- (third);
\draw[->] (third) -- (fourth);
\draw[->] (fourth) -- (fifth);

\draw[->] (fourth) -- (sixth);
\draw[->] (sixth) -- (seventh);
\draw[->] (seventh) -- (eigth);
\draw[->] (eigth) -- (second);
\end{tikzpicture}

\end{document}

which yields

enter image description here

what can I do to make it more pretty with no spacing between the non-labeled nodes (I have tried make them coordinates instead of empty nodes, but it didn't work properly with \coordinate (...) [right=of ...];).

I have also tried bending the arrows without luck. Should it be \draw (A) -- edge[bend right] (B);?

3
  • \draw (A) edge[bend right] (B); or \draw (A) to[bend right] (B); or \draw (A) to[out=angle,in=angle] (B); Sep 20 '16 at 8:04
  • Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you fi you give us compliable code to start from.
    – user30471
    Sep 20 '16 at 8:17
  • Sure. I have updated expanded my code now :-)
    – Jamgreen
    Sep 20 '16 at 8:19
3

I think the graphs library is a good starting point with many examples in the manual:

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{graphs,positioning,arrows}


\begin{document}
\begin{tikzpicture}[%
node distance=5mm,
>=stealth',
black!50,
text=black,
graphs/every graph/.style={edges=rounded corners},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}},
hv path/.style={to path={-| (\tikztotarget)}},
vh path/.style={to path={|- (\tikztotarget)}},
box/.style={%
    rectangle,
    minimum size=6mm,
    draw=black,
    top color=white, 
    bottom color=red!50!black!20, 
},
rounded/.style={%
    rectangle,minimum size=6mm,rounded corners=3mm,
    draw=black!50,
    top color=white,bottom color=black!20,
},
start/.style={%
    circle,inner sep=2pt,minimum size=2pt,fill=white,draw=black!50,
},
end/.style={%
    start,
},
]

\node[start] (start) {};
\node[right=of start] (p1) {};
\node[box,right=of p1] (term) {term};
\node[rounded,below=of term] (plus)  {+};
\node[right=of term] (p2) {};
\node[end,right=of p2] (end) {};

\graph [use existing nodes] {
    start -> term -> end;
    (plus) ->[hv path] (p1);
    (p2) ->[vh path] (plus);
};

\end{tikzpicture}
\end{document}

Edit: This is more similar to your example:

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{graphs,positioning,arrows,calc}


\begin{document}
\begin{tikzpicture}[%
node distance=5mm,
>=stealth',
black!50,
text=black,
graphs/every graph/.style={edges=rounded corners},
vloop/.style={to path={-- ++(#1,0) |- (\tikztotarget)}},
hloop/.style={to path={-- ++($(0,0)-(#1,0)$) |- (\tikztotarget)}},
hv path/.style={to path={-| (\tikztotarget)}},
vh path/.style={to path={|- (\tikztotarget)}},
box/.style={%
    rectangle,
    minimum size=6mm,
    draw=black,
    top color=white, % a shading that is white at the top...
    bottom color=red!50!black!20, % and something else at the bottom
    % Font
    %font=\itshape
},
rounded/.style={%
    rectangle,minimum size=6mm,rounded corners=3mm,
    draw=black!50,
    top color=white,bottom color=black!20,
},
start/.style={%
    circle,inner sep=1pt,minimum size=1pt,fill=white,draw=black!50,
},
end/.style={%
    start,
},
junction/.style={circle,inner sep=0pt,minimum size=0pt},
]

\node[start] (start) {};
\node[junction,right=of start] (p1) {};
\node[box,right=of p1] (term) {term};
\node[rounded,below=of term] (plus)  {+};
\node[junction,right=of term] (p2) {};
\node[end,right=of p2] (end) {};

\graph [use existing nodes] {
start -> p1 -> term -> p2 -> end;
(plus) ->[hloop] term;
(term) ->[vloop] plus;
};
\end{tikzpicture}
\end{document}
1
  • If you use \coordinate rather than \node for the joining points, you can avoid the spaces.
    – cfr
    Sep 20 '16 at 15:44

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.