5

What's the best way to draw $\to^*$ arrows in TikZ drawings? The best I've managed to come up with so far is

\draw[->] (A) to node[very near end] {$*$} (B);
  • I'm not sure that Ι understand your question – karathan Mar 24 '13 at 20:07
  • I have a relation $\to^*$ in my work, and I'd like to draw a TikZ diagram involving this relation. I know how to draw arrows and label them (and different arrowheads can be specified in a straightforward way), but I don't know if there's an easy/natural way to specify this kind of symbol. Ideally, I'd like something like \draw[->*] for example. – Alex Mar 24 '13 at 20:16
  • 1
    Can you give a minimal working example (MWE)? – karathan Mar 24 '13 at 20:32
  • One possibility (though not ideal): \tikz{\draw[->,semithick] (0,0) -- (.35,0) node[above right, xshift=-.8ex,yshift=-.5ex] {\scriptsize $*$};} – jub0bs Mar 24 '13 at 20:33
  • 2
    Another possibly is to add to* as an arrow. Could you post either a MWE or a picture of how the star should be aligned in relation to the arrow? – Qrrbrbirlbel Mar 24 '13 at 20:51
11

Here some ideas.

The first, a to path with an extra node consisting of $ {} ^ * $.

The second introduces two to arrows, namely to* and *to. As the arrow will get transformed I have added the *to arrow for the start line where the asterisk should appear on the left side of the line.

The code has—commented out—a solution with an original $\scriptstyle *$ inside a \pgftext command which does not work when the arrow is used more than once in the document.

Code

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

Output

enter image description here

  • 2
    Possible improvement: Defining an arrow tip with only the * and combine that with > so that >* can be used similar to >| and the > option. See also TikZ arrow tip is displaced. – Qrrbrbirlbel Oct 6 '13 at 14:12

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.