tikz 中箭头旁边的星号

tikz 中箭头旁边的星号

在 TikZ 绘图中绘制$\to^*$箭头的最佳方法是什么?到目前为止,我能想到的最好的方法是

\draw[->] (A) to node[very near end] {$*$} (B);

答案1

这里有一些想法。

第一个是 ,to path带有一个由 组成的额外节点$ {} ^ * $

第二个引入了两个箭头,即to**to。由于箭头会变形,我添加了*to起始线的箭头,星号应出现在该线的左侧。

代码中有一个注释掉的解决方案,其中的原始命令在$\scriptstyle *$文档\pgftext中多次使用箭头时不起作用。

代码

\documentclass{article}
\usepackage{tikz}
\usepgflibrary{plotmarks}
\tikzset{
    to*/.style={
        shorten >=.25em,#1-to,
        to path={-- node[inner sep=0pt,at end,sloped] {${}^*$} (\tikztotarget) \tikztonodes}
    },
    to*/.default=
}

\makeatletter
\pgfarrowsdeclare{to*}{to*}
{
  \pgfutil@tempdima=-0.84pt%
  \advance\pgfutil@tempdima by-1.3\pgflinewidth%
  \pgfutil@tempdimb=0.21pt%
  \advance\pgfutil@tempdimb by.625\pgflinewidth%
  \advance\pgfutil@tempdimb by2.5pt%
  \pgfarrowsleftextend{+\pgfutil@tempdima}
  \pgfarrowsrightextend{+\pgfutil@tempdimb}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{0.8\pgflinewidth}
  \pgfsetdash{}{+0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{-2.75\pgfutil@tempdima}{2.5\pgfutil@tempdima}}
  {\pgfqpoint{0pt}{0.25\pgfutil@tempdima}}
  {\pgfqpoint{0.75\pgfutil@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfqpoint{0pt}{-0.25\pgfutil@tempdima}}
  {\pgfqpoint{-2.75\pgfutil@tempdima}{-2.5\pgfutil@tempdima}}
  {\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfusepathqstroke
  \begingroup
    \pgftransformxshift{2.5pt}
    \pgftransformyshift{2pt}
    \pgftransformscale{.7}
    \pgfuseplotmark{asterisk}
  \endgroup
%  \pgftext[left,y=2pt]{$\scriptstyle *$}
}

\pgfarrowsdeclare{*to}{*to}
{
  \pgfutil@tempdima=-0.84pt%
  \advance\pgfutil@tempdima by-1.3\pgflinewidth%
  \pgfutil@tempdimb=0.21pt%
  \advance\pgfutil@tempdimb by.625\pgflinewidth%
  \advance\pgfutil@tempdimb by2.5pt%
  \pgfarrowsleftextend{+\pgfutil@tempdima}
  \pgfarrowsrightextend{+\pgfutil@tempdimb}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{0.8\pgflinewidth}
  \pgfsetdash{}{+0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{-2.75\pgfutil@tempdima}{2.5\pgfutil@tempdima}}
  {\pgfqpoint{0pt}{0.25\pgfutil@tempdima}}
  {\pgfqpoint{0.75\pgfutil@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfqpoint{0pt}{-0.25\pgfutil@tempdima}}
  {\pgfqpoint{-2.75\pgfutil@tempdima}{-2.5\pgfutil@tempdima}}
  {\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfusepathqstroke
  \begingroup
    \pgftransformxshift{2.5pt}
    \pgftransformyshift{-2pt}
    \pgftransformscale{.7}
    \pgfuseplotmark{asterisk}
  \endgroup
%  \pgftext[left,y=-2pt]{$\scriptstyle *$}
}

\makeatother

\newcommand*{\testtostar}[1]{%
\tikz[baseline=(A.base)]{
    \node (A) {$A$}; \node at (1,0) (B) {$B$};
    \draw[arrows=#1] (A) -- (B);}%
}
\begin{document}
$ A \to^* B$
\tikz[baseline=(A.base)]{
    \node (A) {$A$}; \node at (1,0) (B) {$B$};
    \path (A) edge[to*] (B);}

\testtostar{-to*}
\testtostar{to*-}
\testtostar{to*-to*}

\testtostar{-*to}
\testtostar{*to-}
\testtostar{*to-*to}

\testtostar{*to-to*}
\testtostar{to*-*to}
\end{document}

输出

在此处输入图片描述

相关内容