3

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):

enter image description here

I guess the error must have something to do with \pgfarrowsrightextend, but I don't seem to get how it works.

4

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. The quick 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 its gridded option is only used so one can easily spot the coordinates (0,0) and (1,0). The second picture is the result of opacity=.5 and shows the line and the arrow tip separately.

Code

\documentclass[tikz,convert=false]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds}

\makeatletter
\pgfarrowsdeclare{ipe arrow}{ipe arrow}{%
  \pgfutil@tempdima=5pt\relax
  \advance\pgfutil@tempdima-1.5\pgflinewidth
  \pgfarrowsleftextend{+-\pgfutil@tempdima}%
  \pgfarrowsrightextend{+1.5\pgflinewidth}%
}{%
  \pgftransformshift{\pgfqpoint{1.5\pgflinewidth}{0pt}}%
  \pgfpathmoveto{\pgfpointorigin}%
  \pgfpathlineto{\pgfqpoint{-5pt}{-1.666pt}}%
  \pgfpathlineto{\pgfqpoint{-5pt}{+1.666pt}}%
  \pgfpathclose
  \pgfusepathqfill
}
\makeatother
\begin{document}

Output

enter image description here

enter image description here

  • Interesting results with line width=3.3333pt or greater. ;) – Qrrbrbirlbel Jul 26 '13 at 13:34
  • Make a polyline and add fill=red :) (hoping that I'm reading the code correctly ) – percusse Jul 26 '13 at 13:52
  • @percusse Happens with every other arrow tip (that uses some sort of filling of course), too: latex, latex', stealth and, especially interesting because it also uses a stroke, stealth'. – Qrrbrbirlbel Jul 26 '13 at 14:02
  • Not a criticism. I find it funny that fill and transparency groups are not implemented. I guess Luigi's new arrow library is similar. – percusse Jul 26 '13 at 14:11
  • @percusse Ah, okay. :) I guess it is a bug-feature. Some of the arrow tips can explicitly be used for filling. Otherwise, better fill the path first and then use it again to draw an arrow. The transparency group is really annoying (or it would be if I'd use transparency), though I have exploited this before to show how stuff works and it also works for patterns. – Qrrbrbirlbel Jul 26 '13 at 15:21

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.