TikZ-“圆圈”箭头

TikZ-“圆圈”箭头

在下面的代码中,我想在一个灰色的“圆圈”箭头内添加一个文本,就像下面的丑陋绘画一样。

截屏

在此处输入图片描述

代码

\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}

答案1

更新:新版本支持样式,以及新示例:

此命令很有用:

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

它可以用作 Tikz 图片的一部分,如下所示:

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

结果

答案2

我的解决方案提供

  • 新的节点形状circle arrow
  • 三个键的功能与操作员的键完全相同arc
    • /qrr/circle arrow/start angle
    • /qrr/circle arrow/end angle
    • /qrr/circle arrow/delta angle
  • /qrr/circle arrow/arrows以及设置弧线箭头的键。

我还添加了一些样式来预设圆的方向和开口部分。希望它们是不言自明的(见下面的示例)。

代码

\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}

输出

在此处输入图片描述

答案3

就像这样,具有适当的值:

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

相关内容