2

I have a custom TikZ arrow head called myarrow. How can I turn it into a shape? I want to be able place it wherever I want without needing an edge underneath, with a command like this:

\node [myarrowshape] at (0,0) {};
  • Do you want realy a shape with text inside the arrow, or you want just to be able to drop your arrow at some place ? – Kpym Jan 12 '15 at 21:08
  • Just drop the arrow, no text. – Jamie Vicary Jan 12 '15 at 23:16
  • Some code, please? Such as the definition of said arrow head? (Or are you concerned about ceding intellectual property rights in it?) It is much easier to work on a concrete example than to first construct one which you hope is relevantly similar, but may not be, and then work on that. Also, you limit helpers needlessly. I've never defined my own arrow head. So I don't know how to and can't work on the question without first learning that. But I've defined lots of pics, so if I didn't have the defining-head obstacle, the question might be tempting. But I do, so it is rather less so. – cfr Jan 13 '15 at 2:13
  • Tl;dr: never make the mistake of assuming that only those who know at least what you know can possibly help you. – cfr Jan 13 '15 at 2:18
  • Probably a better title for your question in this case will be "How to drop a tikz arrow at given coordinates ?". – Kpym Jan 13 '15 at 8:07
5

If what you want is just to be able to drop arrow somewhere, here is one possibility (with two versions). Both versions use the same method :decorations.markings with \arrow.

UPDATE : As the first version has some drawbacks, here is a modification using pic in place of path picture.

  • You can set the arrow like this pic{arrow=latex} or by changing the default one.
  • To scale the arrow you can change the line width, for exemple like pic[line width=3pt]{arrow}.
  • The arrow is not centered at the coordinate. If you want to make it centered you can look at this question.

Here is the code producing the same (up to random choice) image as the first method.

\documentclass[tikz,border=7pt,convert={density=1400}]{standalone}
\usetikzlibrary{decorations.markings}
%\usetikzlibrary{arrows.meta}
\tikzset{
  markarrow/.style={
    decoration={ markings,
      mark=at position .5 with {\arrow{#1}}
    },
    postaction={decorate}
  },
  arrow/.pic = {
    \path[pic actions, markarrow={#1}] (-1pt,0) -- (1pt,0);
  },
  pics/arrow/.default={stealth}
}
\begin{document}
  \begin{tikzpicture}

    \foreach \i in {1,...,100}
      \pic[rotate={random(0,360)}, opacity={rnd}, blue]
          at ({2*rnd},{2*rnd}) {arrow};

    \pic[red] at (1,1) {arrow};

  \end{tikzpicture}
\end{document}

enter image description here

First version: Using the syntax asked in the question.

\documentclass[tikz,border=7pt,convert={density=1400}]{standalone}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\tikzset{
  markarrow/.style={
    decoration={ markings,
      mark=at position .5 with {\arrow[#1]{stealth}}
    },
    postaction={decorate}
  },
  myarrow/.style={ inner sep = 7pt,
    path picture={
      \path[markarrow={#1}] ([xshift=-1pt]path picture bounding box.center) --++(2pt,0);
    }
  }
}
\begin{document}
  \begin{tikzpicture}

    \foreach \i in {1,...,100}
      \node[rotate={random(0,360)}, opacity={rnd}, myarrow=blue]
          at ({2*rnd},{2*rnd}) {};

    \node[myarrow=red] at (1,1) {};

  \end{tikzpicture}
\end{document}

This version hase some drawbacks:

  • path picture is not designed for this, but for fill with picture;
  • by design it is clipped inside the node, so if we want to scale the arrow, we have to scale the containing node too. As a consequence scaling with this method is tricky.
  • 1
    I like the idea of using pic... – Jamie Vicary Jan 12 '15 at 23:16
  • Here is a pic version now. – Kpym Jan 13 '15 at 8:02

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.