Custom shape (possibly an image) as tikz arrow shape
The package tikz-cd
provides a chance to use arbitrary thing as arrow tips. For example
\documentclass[border=10pt,tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}
\def\POfourthree{PO_4^{3-}}
\def\exampleimagea{\includegraphics[height=2ex]{example-image-a}}
\tikzset{
PO43/.tip={Glyph[glyph math command=POfourthree,glyph length=3em]},
exA/.tip={Glyph[glyph math command=exampleimagea,glyph length=3ex]},
}
\tikz[line width=.53pt]\draw[-PO43](0,0)to[bend right](3,0);
\tikz[line width=.53pt]\draw[-exA](0,0)to[bend right](3,0);
\tikz[line width=.53pt]\draw[PO43-exA](0,0)to[bend right](3,0);
\end{document}
As you can see, the thing might be clipped inappriately. Here is how to fix it
\makeatletter
\pgfqkeys{/pgf/arrow keys}{
glyph width/.code={\pgfarrowsaddtooptions{\pgfmathsetlengthmacro\tikzcd@glyph@wid{#1}}},
}
\pgfdeclarearrow{
name=Tall Glyph,
cache=false,
bending mode=none,
parameters={\tikzcd@glyph@len,\tikzcd@glyph@wid,\tikzcd@glyph@shorten},
setup code={
\pgfarrowssettipend{\tikzcd@glyph@len\advance\pgf@x by\tikzcd@glyph@shorten}},
defaults={
glyph axis=axis_height,
glyph length=+0.9ex,
glyph width=+3.0ex,
glyph shorten=+-0.1ex},
drawing code={
\show\tikzcd@glyph@wid
\pgfpathrectangle{\pgfpoint{+0pt}{.5ex-.5*\tikzcd@glyph@wid}}%
{\pgfpoint{+\tikzcd@glyph@len}{\tikzcd@glyph@wid}}%
\pgfusepathqclip%
\pgftransformxshift{+\tikzcd@glyph@len}%
\pgftransformyshift{+-\tikzcd@glyph@axis}%
\pgftext[right,base]{\tikzcd@glyph}}}
\tikzset{
PO43/.tip={Tall Glyph[glyph math command=POfourthree,glyph length=3em,glyph width=4ex]},
exA/.tip={Tall Glyph[glyph math command=exampleimagea,glyph length=3ex,glyph width=4ex]},
}
\tikz[line width=.53pt]\draw[-PO43](0,0)to[bend right](3,0);
\tikz[line width=.53pt]\draw[-exA](0,0)to[bend right](3,0);
\tikz[line width=.53pt]\draw[PO43-exA](0,0)to[bend right](3,0);
Not really an arrow (I tried but failed), but it can be useful nevertheless:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{decorations.markings}
\def\hand{\includegraphics[width=3mm]{hand.png}}
\tikzset{
-hand/.style = {
decoration = {
markings,
mark=at position -4mm with { \node[anchor=190,transform shape, inner sep=0pt] {\hand}; } },
postaction = decorate,
shorten >=4mm,
}
}
\begin{document}
\begin{tikzpicture}
\node[draw] (start) at (0,0) {Start};
\node[draw] (finish) at (1,2) {Finish};
\draw[-hand] (start) to[bend left] (finish);
\draw[-hand] (finish) to[bend left] (start);
\end{tikzpicture}
\end{document}
Update: dealing with edges
This trick can also be used with edge
s. The following example shows how (the -hand
option has to be used in the edge
):
\tikzset{
-hand/.style = {
decoration = {
markings,
mark=at position -3mm with { \node[anchor=west,transform shape, inner sep=0pt] {\hand}; } },
postaction = decorate,
shorten >=3mm,
}
}
\begin{tikzpicture}
\node[draw] (start) at (0,0) {Start};
\node[draw] (finish) at (1,2) {Finish};
\draw (start) edge[bend right, -hand] (finish)
(finish) edge[bend right, -hand] (start);
\end{tikzpicture}
Result:
Update's update
For some unknown reason, the "edges" version behaves better than the path version, in the sense that the required position of the "arrowhead" as decoration matches exactly the width of the included picture (-3mm), and the same value (3mm) can be used for option shorten >
. In the path version extra manual finetuning was required, but this is not neccessary in the edge
version. This allows to easily parametrize the size of the arrow head as follows:
\tikzset{
-hand/.style = {
decoration = {
markings,
mark=at position -#1 with {
\node[anchor=west, transform shape, inner sep=0pt]
{\includegraphics[width=#1]{hand.png}};
}
},
postaction=decorate,
shorten >=#1,
},
-hand/.default=3mm,
}
This way, we can specify the size of the hand (it will be 3mm by default), as the following example shows:
\begin{tikzpicture}
\node[draw] (start) at (0,0) {Start};
\node[draw] (finish) at (1,2) {Finish};
\draw (start) edge[bend right, -hand] (finish)
(finish) edge[bend right, -hand=5mm] (start);
\end{tikzpicture}