11

In the code below, I would like to add one text inside one "circled" arrow in gray like in the following ugly draw.

Screenshot

enter image description here

Code

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{arrows,shadows,positioning}

    \tikzset{
        frame/.style={
            rectangle, draw,
            text width = 6em, text centered,
            minimum height = 4em, drop shadow, fill=lime!40,
            rounded corners,
        },
        line/.style={
            draw, -latex', rounded corners = 3mm,
        }
    }


\begin{document}

\begin{tikzpicture}[font=\small\sffamily\bfseries,very thick,node distance = 4cm]
    \node [frame] (pop) {Population};
    \node [above=2cm, left of=pop] (init) {Initialisation};
    \node [below=2cm, left of=pop] (term) {Termination};
    \node [frame, above=2cm, right of=pop] (parents)  {Parents};
    \node [frame, below=2cm, right of=pop] (off)  {Offspring};

    \path [line] (parents)
     -- node[right,align=left,pos=.5] {Recombination\\[3mm]Mutation}
     (off);
    \path [line] (init) |- (pop.170);
    \path [line] (pop.190) -| (term);
    \path [line] (off) -| node[below,pos=.25, align=center] {Survivor\\ selection}(pop);
    \path [line] (pop) |- node[above,pos=.75, align=center] {Parents\\ selection}(parents);
\end{tikzpicture}

\end{document}
15

UPDATED: New version supporting styles, and new example:

This command can be useful:

\def\circledarrow#1#2#3{ % #1 Style, #2 Center, #3 Radius
\draw[#1,->] (#2) +(80:#3) arc(80:-260:#3);
}

It can be used as part of a Tikz picture like this:

\begin{tikzpicture}
\node (text) {$n$ times};
\circledarrow{ultra thick, gray}{text}{1cm};
\end{tikzpicture}

Result

  • my question becomes : "How to put this at the center of the triangle Population-Parents-Offspring ?". – projetmbc Jan 24 '13 at 17:14
  • There's no need of the final ; for \circledarrow within tikzpicture unless you define it as \def\circledarrow#1#2#3;{. Only in that case you necessary need to use it. – Claudio Fiandrino Jan 24 '13 at 17:14
  • @projetmbc check "barycentric systems" in the PGF/Tikz manual – Lionel MANSUY Jan 24 '13 at 17:29
  • @ClaudioFiandrino Yes, I know, but it doesn't hurt either (all text out of a tikz command inside a tikz environment is ignored, as it is the case for that semicolon). And I prefer how to looks the code with the ; – JLDiaz Jan 24 '13 at 17:59
  • @LionelMANSUY : it seems that I need to define coordinates. Isn't it ? – projetmbc Jan 24 '13 at 19:26
14

My solution provides

  • a new node shape circle arrow,
  • three keys that work exactly like the keys for the arc operator:
    • /qrr/circle arrow/start angle,
    • /qrr/circle arrow/end angle,
    • /qrr/circle arrow/delta angle,
  • and a key /qrr/circle arrow/arrows that sets the arrows for the arc.

I have also added a few styles the pre-set the direction and the open part of the circle. Hopefully they are self-explanatory (see the example below).

Code

\documentclass[tikz,border=4pt]{standalone}
\usetikzlibrary{arrows,matrix}
\makeatletter
\tikzset{
    /qrr/circle arrow/.cd,
    start angle/.initial={},
    delta angle/.initial={},
    end angle/.initial={},
    arrows/.estore in=\qrr@ca@arrow,
    arrows=-
}
\pgfdeclareshape{circle arrow}{
    \inheritsavedanchors[from=circle] \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{north}      \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{north east} \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{west}       \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{mid}        \inheritanchor[from=circle]{mid west}
    \inheritanchor[from=circle]{mid east}   \inheritanchor[from=circle]{base}
    \inheritanchor[from=circle]{base west}  \inheritanchor[from=circle]{base east}
    \inheritanchor[from=circle]{south}      \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{south east}
    \backgroundpath{
        \pgfkeysgetvalue{/qrr/circle arrow/start angle}\qrr@ca@s
        \pgfkeysgetvalue{/qrr/circle arrow/end angle}\qrr@ca@e
        \pgfkeysgetvalue{/qrr/circle arrow/delta angle}\qrr@ca@d
        \ifx\qrr@ca@s\pgfutil@empty%
            \pgfmathsetmacro\qrr@ca@s{\qrr@ca@e-\qrr@ca@d}%
        \else
            \ifx\qrr@ca@e\pgfutil@empty%
                \pgfmathsetmacro\qrr@ca@e{\qrr@ca@s+\qrr@ca@d}%
            \fi%
        \fi
        \pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfpointpolar{\qrr@ca@s}{\radius}}}%
        \pgfpatharc{\qrr@ca@s}{\qrr@ca@e}{\radius}%
        \pgfkeys{/tikz/arrows/.expand once=\qrr@ca@arrow}%
    }
}
\makeatother
\tikzset{% the first two styles are internal, they do not work alone!
    turn left/.style={/tikz/shape=circle arrow,/qrr/circle arrow/arrows=->,/qrr/circle arrow/delta angle=340},
    turn right/.style={/tikz/shape=circle arrow,/qrr/circle arrow/arrows=<-,/qrr/circle arrow/delta angle=340},
    turn left north/.style  = {/tikz/turn left,  /qrr/circle arrow/start angle=100} ,
    turn left east/.style   = {/tikz/turn left,  /qrr/circle arrow/start angle=10},
    turn left south/.style  = {/tikz/turn left,  /qrr/circle arrow/start angle=280},
    turn left west/.style   = {/tikz/turn left,  /qrr/circle arrow/start angle=190},
    turn right north/.style = {/tikz/turn right, /qrr/circle arrow/start angle=100} ,
    turn right east/.style  = {/tikz/turn right, /qrr/circle arrow/start angle=10},
    turn right south/.style = {/tikz/turn right, /qrr/circle arrow/start angle=280},
    turn right west/.style  = {/tikz/turn right, /qrr/circle arrow/start angle=190},
}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,draw=none,row sep=1em,column sep=1em,
    every node/.style={draw=gray,ultra thick, inner sep=.5em,font=$n$ times}
] (m) {
    |[turn left north]|  & |[turn left east]|   \\
    |[turn left west]|   & |[turn left south]|  \\
    |[turn right north]| & |[turn right east]|  \\
    |[turn right west]|  & |[turn right south]| \\
};
\end{tikzpicture}
\end{document}

Output

enter image description here

  • Of course, defining a new node shape is the right way to do it, but I was too lazy. +1 – JLDiaz Jan 25 '13 at 0:16
5

Just like this, with appropriates values:

\draw[->,>=latex'] (pointA) arc[radius=1cm,start angle=0,delta angle=270];

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.