Is it possible to change the size of an arrowhead in TikZ/PGF?
Update 2013-02-27
This code is now superseded by the new arrows.meta
library bundled with TikZ 3.0.0.
See an example of use in Ignasi's answer below.
Update 2013-01-23
The development version of the complete code is now available on sourceforge. The old arrowhead
key is now replaced by arrow head
to give consistency with the other keywords in the package.
Update 2012-11-13
I edited all the predefined arrow tips and those in the arrows library, except for the "almost 0d" ones (serif cm
, space
and all the line caps arrows) and implies
(because I think it depends indeed on the line width), whose original code has been included for completeness, so that one can find all the previously available arrows in just a single code.
For "almost 1d" arrow tips (hooks like, and bracket like), the arrowhead value sets the height of the tip, instead of its length (for left and right variants, the height of the whole hook).
The code of the to new
arrow has now been fixed. For 45 degrees arrows, the amplitude of the tip is actually 45° and not 46° as in the original code.
Of course, you can use the new arrows as markings too.
I can't upload the new code because it exceeds the size limit for the answers, but I'm posting a picture of the result of the new test file. I sent an email to Till Tantau asking to turn the code in a new TikZ
library and we'll see.
I'm not a TikZ
guru, so I've done what I could. Therefore everyone is invited to improve the code, and I really think it can be improved. Save the new arrows code as arrowsnew.tex
and load it by means of \input{arrowsnew}
in your preamble. There are nine new arrows named latexnew
, latexnew reversed
, latex'new
, latex'new reversed
, onew
, squarenew
, stealthnew
, stealthnew reversed
and tonew
(or >new
). It works like this: if you call an arrow without the arrowhead
key or you don't assign it any value, the original code is used, so that the new code can fully replace the old one. Otherwise, if you assign a value to the arrowhead
key, the lenght of the arrowhead will be set to <value>
. At the moment, the tonew
arrow is slightly different from the original. Please, don't directly edit the code, but feel free to reuse/edit it in a new answer.
The result of the new code 2012-11-13
The old test code
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\input{arrowsnew}
\tikzset{options/.code={\tikzset{#1}}} % just to compact the code
\begin{document}
\begin{tikzpicture}
\draw [red] (2,-24.2) -- (2,0.2) node [above right, black] {1 cm};
\draw [red] (3,-24.2) -- (3,0.2);
\foreach \x [count=\i from 0] in {
{latex-latexnew},
{latex-latexnew, arrowhead=1cm},
{latex-latexnew, arrowhead=1cm, line width=1pt},
{latex reversed-latexnew reversed, arrowhead=1cm, line width=1pt},
{latex'-latex'new},
{latex'-latex'new, arrowhead=1cm},
{latex'-latex'new, arrowhead=1cm, line width=2pt},
{latex' reversed-latex'new reversed, arrowhead=1cm, line width=2pt},
{o-onew},
{o-onew, arrowhead=1cm},
{o-onew, arrowhead=1cm, line width=2pt},
{square-squarenew},
{square-squarenew, arrowhead=1cm},
{square-squarenew, arrowhead=1cm, ultra thick},
{stealth-stealthnew},
{stealth-stealthnew, arrowhead=1cm},
{stealth-stealthnew, arrowhead=1cm, ultra thick},
{stealth reversed-stealthnew reversed, arrowhead=1cm, ultra thick},
{to-tonew},
{to-tonew, arrowhead=1cm}
}
{
\draw [options/.expand once=\x] (0,-1.2*\i) -- (3,-1.2*\i) node [right] {\x};
}
\draw [<->new, arrowhead=0.25in, line width=4pt] (0,-24) -- (3,-24)
node [right] {\verb!<->!new, arrowhead=0.25in, line width=4pt};
\draw [red] (3,-23.2) ++ (-0.25in,0) -- ++(0,-1.6) node [below,black] {0.25 in};
\end{tikzpicture}
\end{document}
The result
The old arrowsnew code (superseded)
% This is not an official TikZ library. Use at your own risk!
\makeatletter
% alternative latex arrow
\pgfarrowsdeclare{latexnew}{latexnew}
{
\ifdim\pgfgetarrowoptions{latexnew}=-1pt%
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{latexnew}%
\divide\pgfutil@tempdima by 10%
\fi%
\pgfarrowsleftextend{+-1\pgfutil@tempdima}%
\pgfarrowsrightextend{+9\pgfutil@tempdima}%
}
{
\ifdim\pgfgetarrowoptions{latexnew}=-1pt%
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{latexnew}%
\divide\pgfutil@tempdima by 10%
\pgfsetlinewidth{0bp}%
\fi%
\pgfpathmoveto{\pgfqpoint{9\pgfutil@tempdima}{0pt}}
\pgfpathcurveto
{\pgfqpoint{6.3333\pgfutil@tempdima}{.5\pgfutil@tempdima}}
{\pgfqpoint{2\pgfutil@tempdima}{2\pgfutil@tempdima}}
{\pgfqpoint{-1\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
\pgfpathlineto{\pgfqpoint{-1\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
\pgfpathcurveto
{\pgfqpoint{2\pgfutil@tempdima}{-2\pgfutil@tempdima}}
{\pgfqpoint{6.3333\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
{\pgfqpoint{9\pgfutil@tempdima}{0pt}}
\pgfusepathqfill
}
% alternative latex reversed arrow
\pgfarrowsdeclarereversed{latexnew reversed}{latexnew reversed}{latexnew}{latexnew}
% alternative latex' arrow
\pgfarrowsdeclare{latex'new}{latex'new}
{
\ifdim\pgfgetarrowoptions{latex'new}=-1pt%
\pgfutil@tempdima=0.28pt%
\advance\pgfutil@tempdima by.3\pgflinewidth%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{latex'new}%
\divide\pgfutil@tempdima by 10%
\fi%
\pgfarrowsleftextend{+-4\pgfutil@tempdima}
\pgfarrowsrightextend{+6\pgfutil@tempdima}
}
{
\ifdim\pgfgetarrowoptions{latex'new}=-1pt%
\pgfutil@tempdima=0.28pt%
\advance\pgfutil@tempdima by.3\pgflinewidth%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{latex'new}%
\divide\pgfutil@tempdima by 10%
\pgfsetlinewidth{0bp}%
\fi%
\pgfpathmoveto{\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
\pgfpathcurveto
{\pgfqpoint{3.5\pgfutil@tempdima}{.5\pgfutil@tempdima}}
{\pgfqpoint{-1\pgfutil@tempdima}{1.5\pgfutil@tempdima}}
{\pgfqpoint{-4\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
\pgfpathcurveto
{\pgfqpoint{-1.5\pgfutil@tempdima}{1\pgfutil@tempdima}}
{\pgfqpoint{-1.5\pgfutil@tempdima}{-1\pgfutil@tempdima}}
{\pgfqpoint{-4\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
\pgfpathcurveto
{\pgfqpoint{-1\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}
{\pgfqpoint{3.5\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
{\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
\pgfusepathqfill
}
% alternative latex' reversed arrow
\pgfarrowsdeclarereversed{latex'new reversed}{latex'new reversed}{latex'new}{latex'new}
% alternative o arrow
\pgfarrowsdeclare{onew}{onew}
{
\pgfarrowsleftextend{+-.5\pgflinewidth}
\ifdim\pgfgetarrowoptions{onew}=-1pt%
\pgfutil@tempdima=0.4pt%
\advance\pgfutil@tempdima by.2\pgflinewidth%
\pgfutil@tempdimb=9\pgfutil@tempdima\advance\pgfutil@tempdimb by.5\pgflinewidth%
\pgfarrowsrightextend{+\pgfutil@tempdimb}%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{onew}%
\advance\pgfutil@tempdima by -0.5\pgflinewidth%
\pgfarrowsrightextend{+\pgfutil@tempdima}%
\fi%
}
{
\ifdim\pgfgetarrowoptions{onew}=-1pt%
\pgfutil@tempdima=0.4pt%
\advance\pgfutil@tempdima by.2\pgflinewidth%
\pgfutil@tempdimb=0pt%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{onew}%
\divide\pgfutil@tempdima by 9%
\pgfutil@tempdimb=0.5\pgflinewidth%
\fi%
\pgfsetdash{}{+0pt}
\pgfpathcircle{\pgfpointadd{\pgfqpoint{4.5\pgfutil@tempdima}{0bp}}%
{\pgfqpoint{-\pgfutil@tempdimb}{0bp}}}%
{4.5\pgfutil@tempdima-\pgfutil@tempdimb}%
\pgfusepathqstroke
}
% alternative square arrow
\pgfarrowsdeclare{squarenew}{squarenew}
{
\ifdim\pgfgetarrowoptions{squarenew}=-1pt%
\pgfutil@tempdima=0.4pt
\advance\pgfutil@tempdima by.275\pgflinewidth%
\pgfarrowsleftextend{+-\pgfutil@tempdima}
\advance\pgfutil@tempdima by.5\pgflinewidth
\pgfarrowsrightextend{+\pgfutil@tempdima}
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{squarenew}%
\divide\pgfutil@tempdima by 8%
\pgfarrowsleftextend{+-7\pgfutil@tempdima}%
\pgfarrowsrightextend{+1\pgfutil@tempdima}%
\fi%
}
{
\ifdim\pgfgetarrowoptions{squarenew}=-1pt%
\pgfutil@tempdima=0.4pt%
\advance\pgfutil@tempdima by.275\pgflinewidth%
\pgfutil@tempdimb=0pt%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{squarenew}%
\divide\pgfutil@tempdima by 8%
\pgfutil@tempdimb=0.5\pgflinewidth%
\fi%
\pgfsetdash{}{+0pt}
\pgfsetroundjoin
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{1\pgfutil@tempdima}{4\pgfutil@tempdima}}
{\pgfqpoint{-\pgfutil@tempdimb}{-\pgfutil@tempdimb}}}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{-7\pgfutil@tempdima}{4\pgfutil@tempdima}}
{\pgfqpoint{\pgfutil@tempdimb}{-\pgfutil@tempdimb}}}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{-7\pgfutil@tempdima}{-4\pgfutil@tempdima}}
{\pgfqpoint{\pgfutil@tempdimb}{\pgfutil@tempdimb}}}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{1\pgfutil@tempdima}{-4\pgfutil@tempdima}}
{\pgfqpoint{-\pgfutil@tempdimb}{\pgfutil@tempdimb}}}
\pgfpathclose
\pgfusepathqfillstroke
}
% alternative stealth arrow
\pgfarrowsdeclare{stealthnew}{stealthnew}
{
\ifdim\pgfgetarrowoptions{stealthnew}=-1pt%
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{stealthnew}%
\divide\pgfutil@tempdima by 8%
\fi%
\pgfarrowsleftextend{+-3\pgfutil@tempdima}
\pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
\ifdim\pgfgetarrowoptions{stealthnew}=-1pt%
\pgfutil@tempdima=0.28pt%
\pgfutil@tempdimb=\pgflinewidth%
\ifdim\pgfinnerlinewidth>0pt%
\pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
\fi%
\advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{stealthnew}%
\divide\pgfutil@tempdima by 8%
\pgfsetlinewidth{0bp}%
\fi%
\pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
\pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
\pgfpathlineto{\pgfpointorigin}
\pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
\pgfusepathqfill
}
% alternative stealth reversed arrow
\pgfarrowsdeclarereversed{stealthnew reversed}{stealthnew reversed}{stealthnew}{stealthnew}
% alternative to arrow
\pgfarrowsdeclare{tonew}{tonew}
{
\ifdim\pgfgetarrowoptions{tonew}=-1pt%
\pgfutil@tempdima=0.84pt%
\advance\pgfutil@tempdima by1.3\pgflinewidth%
\pgfutil@tempdimb=0.21pt%
\advance\pgfutil@tempdimb by.625\pgflinewidth%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{tonew}%
\pgfarrowsleftextend{+-0.8\pgfutil@tempdima}%
\pgfarrowsrightextend{+0.2\pgfutil@tempdima}%
\fi%
}
{
\ifdim\pgfgetarrowoptions{tonew}=-1pt%
\pgfutil@tempdima=0.28pt%
\advance\pgfutil@tempdima by.3\pgflinewidth%
\pgfutil@tempdimb=0pt,%
\else%
\pgfutil@tempdima=\pgfgetarrowoptions{tonew}%
\multiply\pgfutil@tempdima by 100%
\divide\pgfutil@tempdima by 375%
\pgfutil@tempdimb=0.4\pgflinewidth%
\fi%
\pgfsetdash{}{+0pt}
\pgfsetroundcap
\pgfsetroundjoin
\pgfpathmoveto{\pgfpointorigin}
\pgflineto{\pgfpointadd{\pgfpoint{0.75\pgfutil@tempdima}{0bp}}
{\pgfqpoint{-2\pgfutil@tempdimb}{0bp}}}
\pgfusepathqstroke
\pgfsetlinewidth{0.8\pgflinewidth}
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
{\pgfqpoint{\pgfutil@tempdimb}{0bp}}}
\pgfpathcurveto
{\pgfpointadd{\pgfqpoint{-2.75\pgfutil@tempdima}{2.5\pgfutil@tempdima}}
{\pgfqpoint{0.5\pgfutil@tempdimb}{0bp}}}
{\pgfpointadd{\pgfqpoint{0pt}{0.25\pgfutil@tempdima}}
{\pgfqpoint{-0.5\pgfutil@tempdimb}{0bp}}}
{\pgfpointadd{\pgfqpoint{0.75\pgfutil@tempdima}{0pt}}
{\pgfqpoint{-\pgfutil@tempdimb}{0bp}}}
\pgfpathcurveto
{\pgfpointadd{\pgfqpoint{0pt}{-0.25\pgfutil@tempdima}}
{\pgfqpoint{-0.5\pgfutil@tempdimb}{0bp}}}
{\pgfpointadd{\pgfqpoint{-2.75\pgfutil@tempdima}{-2.5\pgfutil@tempdima}}
{\pgfqpoint{0.5\pgfutil@tempdimb}{0bp}}}
{\pgfpointadd{\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
{\pgfqpoint{\pgfutil@tempdimb}{0bp}}}
\pgfusepathqstroke
}
% alias alternative to arrow
\pgfarrowsdeclarealias{<new}{>new}{tonew}{tonew}
\makeatother
% tip length code
\pgfsetarrowoptions{latexnew}{-1pt}
\pgfsetarrowoptions{latex'new}{-1pt}
\pgfsetarrowoptions{onew}{-1pt}
\pgfsetarrowoptions{squarenew}{-1pt}
\pgfsetarrowoptions{stealthnew}{-1pt}
\pgfsetarrowoptions{tonew}{-1pt}
\pgfkeys{/tikz/.cd, arrowhead/.default=-1pt, arrowhead/.code={
\pgfsetarrowoptions{latexnew}{#1},
\pgfsetarrowoptions{latex'new}{#1},
\pgfsetarrowoptions{onew}{#1},
\pgfsetarrowoptions{squarenew}{#1},
\pgfsetarrowoptions{stealthnew}{#1},
\pgfsetarrowoptions{tonew}{#1},
}}
TikZ v3.0
(among other new features) includes a new arrows.meta
library. It's probably inspired in Luigi's library and deprecates previous arrows
and arrows.spaced
libraries.
With this new library, it's very easy to define arrowhead parameters like length or width depending or not from line width.
\draw[-{Latex[length=3mm,width=5mm]}] (0,0)--(2,0);
will draw an arrow with a Latex
arrowhead 3mm long and 5mm thick. All new arrows have changed their name which now starts with a capital letter to distinguish them from old names. Of course old names are still valid but they don't accept options as in previous example.
It's worth to read section "16 Arrows" in pgfmanual.
Some little examples:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[-latex] (0,0)--(2,0) node[right]{\emph{Old} latex arrow};
\draw[-Latex] (0,-.5)--(2,-.5) node[right]{\emph{new} Latex arrow};
\draw[-{Latex[length=3mm]}] (0,-1)--(2,-1) node[right]{with fixed length};
\draw[-{Latex[width=3mm]}] (0,-1.5)--(2,-1.5) node[right]{with fixed width};
\draw[-{Latex[length=5mm, width=2mm]}] (0,-2)--(2,-2) node[right]{widh fixed length and width};
\draw[-{Latex[red]}] (0,-2.5)--(2,-2.5) node[right]{with colorful tip};
\end{tikzpicture}
\end{document}
More examples about using arrows.meta
:
- Skew an Arrow in a Tikz Diagram
- Custom arrow tip with `arrows.meta` TikZ library
- Adjusting the size of an arrow
Here is a sample of the outward-pointing triangular tips in PGF/TikZ 2.10 (see Section 23 of the 2.10 manual):
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\newcounter{tmp}
\begin{tikzpicture}
\foreach \s in {latex,latex',stealth,triangle 90,triangle 45,angle 90, angle 60} {
\stepcounter{tmp}
\begin{scope}[yshift=-\thetmp cm]
\node[anchor=west] (0,0) {\texttt{\s}};
\draw[arrows={\s-\s}] (3,0) --++ (1,0);
\end{scope}
}
\end{tikzpicture}
\end{document}
If you want something more customized or more specific, read Section 74 of the 2.10 manual of pgf. How much bigger and in what direction are you looking for?