I'm trying to define an arrow for use in tikzpictures
that (similar to the small arrows IPE uses) is 5pt long (tip to end) and 3.333pt wide (base). Here's what I came up with:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\pgfarrowsdeclare{ipe arrow}{ipe arrow}{
\arrowsize=5pt
\pgfarrowsleftextend{-.5\pgflinewidth}
\pgfarrowsrightextend{.5\pgflinewidth}
}
{
\arrowsize=5pt
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{-5pt}{-1.666pt}}
\pgfpathlineto{\pgfpoint{-5pt}{1.666pt}}
\pgfpathlineto{\pgfpointorigin}
\pgfusepathqfill
}
\begin{document}
\begin{tikzpicture}
\draw [<->,>=ipe arrow](0,0) -- (1,0);
\end{tikzpicture}
\end{document}
The line protrudes the arrow's tip, however (see the right side):
I guess the error must have something to do with \pgfarrowsrightextend
, but I don't seem to get how it works.
Best Answer
The
\arrowsize
length is only an auxiliary dimen that you can use to calculate a length. It does not actually have anything to do with size of the arrow tip.The right extend is the length the line will be shorten when the arrow tip is applied. This also does move the origin of the arrow coordinate system (the
\pgfpointorigin
you use). You need to take the same amount into consideration if you want to draw the arrow.The line has to be shortened by
1.5
its width.The left extend (which is actually only needed if you want to combine arrow tips) is then
5pt-1.5\pgflinewidth
. I have used basic TeX dimen calculation and the\pgfutil@tempdima
dimen to calculate this so that the PGF math parser isn't needed (as indicated and forced by the+
in the extend macros).The
\pgftransformshift
macro is used to shift the origin back to the tip of the arrow. Theq
uick version of\pgfpoint
is used as its arguments do not need to get parsed by PGF math, either.Instead of another
\pgfpathlineto
I used\pgfpathclose
(this is the low-level equivalent of-- cycle
) even though you use filling and the closing is implied.The
backgrounds
library and itsgridded
option is only used so one can easily spot the coordinates(0,0)
and(1,0)
. The second picture is the result ofopacity=.5
and shows the line and the arrow tip separately.Code
Output