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) {};
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI 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) {};
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
.
pic{arrow=latex}
or by changing the default one.pic[line width=3pt]{arrow}
.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}
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;