定义自定义 TikZ 箭头(带加号的圆圈)

定义自定义 TikZ 箭头(带加号的圆圈)

我需要在 TikZ 中设计自定义箭头,但到目前为止我还没有太多运气。我已经能够使用箭头元库定义圆形箭头,但我不知道如何在中心添加加号。有人能帮我吗?

带有自定义箭头的箭头

圆形箭头的代码:

\documentclass[border=1pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\tikzset{circleplus/.tip={Circle[open]}}

\begin{document}

\begin{tikzpicture}
  \draw [-circleplus] (0,0)  -- +(1,0);
\end{tikzpicture} 

\end{document} 

答案1

我看不出如何组合现有的箭头,但你可以很容易地修改圆的定义:

在此处输入图片描述

\documentclass[border=1pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\makeatletter


\pgfdeclarearrow{
  name = CircleP,
  defaults = {
    length  = +2.39365pt +3.191538,
    width'  = +0pt 1,
    line width = +0pt 1 1,
  },
  setup code = {
    % Cap the line width at 1/2th of the length
    \[email protected]\pgfarrowlength
    \ifdim\pgf@x<\pgfarrowlinewidth
      \pgfarrowlinewidth\pgf@x
    \fi
    \ifpgfarrowreversed
      \pgfarrowssetlineend{\pgfarrowlength\advance\pgf@x by-.5\pgfarrowlinewidth}
    \else
      \pgfarrowssetlineend{.5\pgfarrowlinewidth}
    \fi
    \pgfarrowssettipend{\pgfarrowlength}
    % The hull:
    \pgfarrowsupperhullpoint{\pgfarrowlength}{.25\pgfarrowwidth}
    \pgfarrowsupperhullpoint{.75\pgfarrowlength}{.5\pgfarrowwidth}
    \pgfarrowsupperhullpoint{.25\pgfarrowlength}{.5\pgfarrowwidth}
    \pgfarrowsupperhullpoint{0pt}{.25\pgfarrowwidth}
    \ifpgfarrowharpoon%
      \pgfarrowshullpoint{0pt}{-.5\pgfarrowlinewidth}
      \pgfarrowshullpoint{\pgfarrowlength}{-.5\pgfarrowlinewidth}
    \fi%
    % The following are needed in the code:
    \pgfarrowssavethe\pgfarrowlinewidth
    \pgfarrowssavethe\pgfarrowlength
    \pgfarrowssavethe\pgfarrowwidth
  },
  drawing code = {
    \pgfsetdash{}{+0pt}
    \ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
    \ifdim\pgfarrowlinewidth=\pgflinewidth\else\pgfsetlinewidth{+\pgfarrowlinewidth}\fi
    \ifpgfarrowharpoon
      \pgfpathmoveto{\pgfqpoint{\pgfarrowlength\advance\pgf@x
          by-.5\pgfarrowlinewidth}{0pt}}
      {%
        \[email protected]\pgfarrowlength
        \advance\pgf@xa by-.5\pgfarrowlinewidth
        \pgftransformxscale{+\the\pgf@xa}
        \[email protected]\pgfarrowwidth
        \advance\pgf@xa by-.5\pgfarrowlinewidth
        \pgftransformyscale{+\the\pgf@xa}
        \pgfpathmoveto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
        \pgfpathlineto{\pgfqpoint{.5\pgfarrowlength}{0pt}}
        \pgfpatharc{0}{180}{1pt}
      }
      \pgfpathclose
    \else%
        \pgfpathmoveto{\pgfqpoint{.25\pgfarrowlength}{0pt}}
        \pgfpathlineto{\pgfqpoint{.75\pgfarrowlength}{0pt}}
        \pgfpathmoveto{\pgfqpoint{.5\pgfarrowlength}{.25\pgfarrowlength}}
        \pgfpathlineto{\pgfqpoint{.5\pgfarrowlength}{-.25\pgfarrowlength}}
      \pgfpathellipse{\pgfqpoint{.5\pgfarrowlength}{0pt}}{\pgfqpoint{.5\pgfarrowlength\advance\pgf@x
          by-.5\pgfarrowlinewidth}{0pt}}{\pgfqpoint{0pt}{.5\pgfarrowwidth\advance\pgf@y
          by-.5\pgfarrowlinewidth}}
    \fi
    \ifpgfarrowopen\pgfusepathqstroke\else\ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi\fi
  },
  parameters = {
    \the\pgfarrowlinewidth,%
    \the\pgfarrowlength,%
    \the\pgfarrowwidth,%
    \ifpgfarrowharpoon h\fi%
    \ifpgfarrowopen o\fi%
    \ifpgfarrowroundjoin j\fi%
  },
}


\tikzset{circleplus/.tip={
CircleP[open]}}

\begin{document}

\begin{tikzpicture}
  \draw [-circleplus] (0,0)  -- +(1,0);
\end{tikzpicture} 

\end{document} 

答案2

您可以定义一个新的箭头尖,如下所述arrows.meta使用TikZ 库自定义箭头

如果您不需要声明新箭头的全部权力,那么您只需使用标记即可:

\documentclass[tikz, border=2pt]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
  -circleplus/.style = {
    decoration={markings,
                mark=at position 1 with
                  {\draw[fill=white] (-2pt,0) circle (2pt);
                   \draw[-] (-3pt,0) -- (-1pt,0) (-2pt,1pt) -- (-2pt,-1pt);
                  }
                },
    postaction={decorate}
  }
}
\begin{document}
\begin{tikzpicture}
  \draw[-circleplus] (0,0) .. controls (.5,0) .. (1,1);
\end{tikzpicture}
\end{document}

标记路径

这不会以通常的方式与其他箭头尖端组合,但您仍然可以使用例如在另一端添加箭头尖端。如果您想使用它,\draw[-circleplus, <-] ...您必须定义一个单独的命令。circleplus-

答案3

@David Carlisle 表示,他

看不到如何组合现有箭头

但他肯定知道如何:把事物放在一起并应用负空间。

\tikzset{circleplus/.tip={.
    Circle[open,length=0 10,sep=0 -7.5]
    Rectangle[length=0 5,width=0 1,sep=0 -3]
    Rectangle[length=0 1,width=0 4]
}}

相关内容