I'm trying to draw an arrow with a bigger head than normal. Is it possible without changing the style of the line itself?
-
2Have you checked out section 58 of the TikZ manual?– Harald Hanche-OlsenCommented Nov 16, 2010 at 13:02
-
2@Harald Yes, just checked. Looks perfect, but it's an overkill for my simple task. Maybe you can suggest an easier way?– yegor256Commented Nov 16, 2010 at 13:48
-
1Not me (not a TikZ user yet), but if there is an easier way, someone will come up with it.– Harald Hanche-OlsenCommented Nov 16, 2010 at 14:16
-
5@HaraldHanche-Olsen LOL you said "58" without a trace of sarcasm. That manual is bigger than most Mercedes User Manuals =P– pukCommented Feb 9, 2012 at 9:28
-
4@puk: Yes indeed, but it does have a table of contents, you know. As well as an index. When I recheck now, however, section 58 doesn't look right anymore (in the 2.1 manual). I guess stuff has been moved about in there. Sorry, I don't have the time right now to find it again. Next time, I should provide the section title as well.– Harald Hanche-OlsenCommented Feb 9, 2012 at 13:00
8 Answers
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},
}}
-
15Excellent answer. Maybe you could submit it as a patch to tikz? Should be quite useful! BTW, also illustrates why one normally shouldn't touch the default arrowhead sizes... (-;– gerritCommented Nov 4, 2012 at 22:16
-
1@gerrit, thank you. I'm going to add more arrowheads, then we'll see. As I told to Andrew Stacey, I don't feel up to design a new package, but I'm contacting Till Tantau and seeing if he is interested in fine tuning my code.– LuigiCommented Nov 5, 2012 at 17:38
-
5
-
2This feature request has been changed to “open-accepted” by Till Tantau: “ I have been thinking about how to integrate this. It seems like a good idea that a general "arrow tip size" should be an always present arrow option, which would simplify most of the code. When I have the time, I will address arrow tips in general and then integrate this.” Commented Aug 31, 2013 at 2:48
-
12I am, admittedly, an infrequent user of tikz, but I cannot readily see how to translate this answer into the actual action of changing the size of an arrowhead. The minimum working example is involved enough that it is difficult to follow. Could you include a true minimum work example, that simply changes the size of the arrowhead? I think the rest of it is great, and clearly quite useful, but it's a bit daunting when one comes to it just looking to make the arrow head twice the normal size... Commented Aug 19, 2015 at 22:58
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
:
-
3Noobs should note that there is no space in-between the hyphen and the arrowhead:
-{Latex}
. I found out the hard way.– ahornCommented May 12, 2017 at 15:04 -
@ahorn Yes, this is the required syntax, a hyphen (
-
) followed and/or preceded (without any space in between) by the kind of desired tip.– IgnasiCommented May 12, 2017 at 17:59 -
Thanks, that really helps a lot. Also, are there other types of arrow head that I could use? I can not find anywhere to explain that. Thanks!– zyyCommented Jun 1, 2017 at 13:48
-
2
-
Here is a sample of the outward-pointing triangular tips in PGF/TikZ 2.10 (see Section 24 "Arrow Tip Library" 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 82 "Arrow Tips" of the 2.10 manual of pgf. How much bigger and in what direction are you looking for?
-
14
-
2This is very useful for people like me still using 2.10 pgf version. Thanks! Commented Jan 4, 2016 at 15:53
Arrow sizes change with the line width. For example for thin
and ultra thick
lines:
If you do not want to have the whole line thicker, you can use the decoration library to add an enlarged arrow to your path. Here are two possibilities:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[
decoration={markings,mark=at position 1 with {\arrow[ultra thick]{>}}},
postaction={decorate}
]
(0,-0.5) -- (1,-0.5);
\draw[
decoration={markings,mark=at position 1 with {\arrow[scale=2]{>}}},
postaction={decorate},
shorten >=0.4pt
]
(0,-1) -- (1,-1);
\end{tikzpicture}
\end{document}
Decorations are explained in chapter 31 "Decoration Library" of the TikZ 2.10 manual. The shorten >=0.4pt
in the last example shortens the line by the default line width (0.4pt) so that it does not extend over the arrow tip (though the effect is nearly invisible for normal thin lines.
-
2decorations is definitely better than coding your own arrow. Good answer. Commented Nov 16, 2010 at 19:23
-
Yes Decoration is lots better but how would i change the line thickness– AkuCommented Jan 21, 2011 at 1:55
i just stumbled on the same problem, but those solutions didn’t fit my need. but i remembered postactions, so i came up with this:
\usetikzlibrary{arrows}
\begin{tikzpicture}
\draw[
-triangle 90,
line width=4mm,
postaction={draw, line width=1cm, shorten >=1cm, -}
] (0,0) -- (2,0);
\end{tikzpicture}
The idea is to choose a line width which yields the right arrow head, and then draw the line again with a fatter line.
Of course it only works when you need the line to be fatter than the head.
-
1No problem. I used it to mimick minecraft’s crafting screen arrow :) Commented Apr 26, 2011 at 9:23
Here is a simple example of how to change all arrow heads in a document. On modern tikz versions, the arrows.meta
tikz library provides a variety of customisable arrow heads and \tikzset
can be used to set the default arrow style:
\documentclass{standalone}
\usepackage{tikz}
% add the following two lines to your document to get bigger arrows
\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[width=3mm,length=3mm]}}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) node[left]{from here} -- (3,1) node[right]{to here};
\end{tikzpicture}
\end{document}
You just need to add the marked two lines to your TeX file to get larger arrow heads. The size is controlled by the two parameters width
and length
. For the above example, the output is as follows:
There is a variety of arrow styles to choose from; the style used in the example is called Latex
. Examples of relatively plain arrow styles include Stealth
, Straight Barb
and Computer Modern Rightarrow
; any of these arrow styles can be used by replacing Latex
in the above example with the corresponding style name. See the other answers and section 16.5 "Reference: Arrow Tips" of the TikZ and PGF manual for a complete list of available arrow styles.
-
1
arrows.meta
library is actually the accepted answer converted into an official library. Luigi is/was involved in the conversion. You can see the note in his answer too.– percusseCommented Mar 22, 2014 at 12:32 -
3@percusse, this is good to know! (I wrote a separate answer just because with all the information provided in the other answers, I struggled a bit to know what I should actually copy/paste into my TeX file.)– jochenCommented Mar 24, 2014 at 17:13
-
1The capital letter in the arrow names is important.
latex
produces an unmodifiable arrow, whileLatex
can be modified. Same for the other styles.– JostCommented Mar 16, 2017 at 15:15
Here's an alternative approach that replaces the arrow-rendering code with a customised version which allows for an extra scale factor to be applied (with only a little more work it would be possible to make it so that you could specify some formula to apply rather than just a linear scale factor and also provide different adjustments for the start and end). It does this by changing the line width just before the arrow is drawn and then restoring it afterwards. (It was derived from some code I had whose aim was to draw an arrow on a double
d line which used the inner line width instead of the outer one. I thought that was from a question here but can't find it now.)
This has the obvious advantage of not needing to modify every single arrow definition!
There are two macros to modify: the one that draws the arrows and the one that shortens the line.
\documentclass{article}
\usepackage{tikz}
%\url{http://tex.stackexchange.com/q/5461/86}
\makeatletter
\pgfkeys{
/pgf/scalable arrows/.code={
\let\pgf@add@arrows@as@needed=\pgf@add@scalable@arrows@as@needed
\let\pgf@shorten@path@as@needed=\pgf@shorten@path@as@needed@for@scalable
},
/pgf/arrow scale factor/.initial=1,
}
\def\pgf@add@scalable@arrows@as@needed{%
\pgfkeysgetvalue{/pgf/arrow scale factor}{\pgf@temp}%
\let\pgf@restorelw=\pgfutil@empty
\ifx\pgf@temp\pgfutil@empty
\else
\edef\pgf@restorelw{\noexpand\pgfsetlinewidth{\the\pgflinewidth}}%
\pgfsetlinewidth{\pgf@temp\pgflinewidth}%
\fi
\ifx\pgf@startarrow\pgfutil@empty%
\else%
\pgflowlevelobj%
{\pgftransformarrow{\pgfpointsecondonpath}{\pgfpointfirstonpath}}
{\pgf@startarrow}%
\fi%
\ifx\pgf@endarrow\pgfutil@empty%
\else%
\pgflowlevelobj%
{\pgftransformarrow{\pgfpointsecondlastonpath}{\pgfpointlastonpath}}
{\pgf@endarrow}%
\fi%
\pgf@restorelw%
}
\def\pgf@shorten@path@as@needed@for@scalable{%
\pgfkeysgetvalue{/pgf/arrow scale factor}{\pgf@temp}%
\let\pgf@restorelw=\pgfutil@empty
\ifx\pgf@temp\pgfutil@empty
\else
\edef\pgf@restorelw{\noexpand\pgfsetlinewidth{\the\pgflinewidth}}%
\pgfsetlinewidth{\pgf@temp\pgflinewidth}%
\fi
\pgfprocesspathextractpoints{\pgf@arrowpath}%
\let\pgf@arrow@next=\pgf@shorten@now%
\ifx\pgf@shorten@start\pgfutil@empty%
\ifx\pgf@shorten@end\pgfutil@empty%
\ifdim\pgf@shorten@end@additional=0pt\relax%
\ifdim\pgf@shorten@start@additional=0pt\relax%
\let\pgf@arrow@next=\relax%
\fi%
\fi%
\fi%
\fi%
\pgf@arrow@next%
\pgf@restorelw%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}[xshift=3cm]
\draw[green] (2,1) -- (2,-3);
\draw[line width=4pt,->] (0,0) -- (2,0);
\draw[line width=4pt,->] (0,-1) -- (2,-1);
\draw[line width=2pt,->] (0,-2) -- (2,-2);
\end{scope}
\begin{scope}[xshift=6cm]
\draw[green] (2,1) -- (2,-3);
\draw[line width=8pt,->] (0,0) -- (2,0);
\draw[line width=2pt,->] (0,-1) -- (2,-1);
\draw[line width=2pt,->] (0,-2) -- (2,-2);
\end{scope}
\begin{scope}[scalable arrows]
\draw[green] (2,1) -- (2,-3);
\draw[arrow scale factor=2,line width=4pt,->] (0,0) -- (2,0);
\draw[arrow scale factor=.5,line width=4pt,->] (0,-1) -- (2,-1);
\draw[line width=2pt,->] (0,-2) -- (2,-2);
\end{scope}
\end{tikzpicture}
\end{document}
The first column has the scalable arrows. The second shows what they would look like with no scaling, the third shows what they would look like with the line width to get that size arrow naturally. The green line is to show that the shortening is correctly applied.
-
1
-
@Jake Doubly so since I had the code lying around anyway (almost). Commented Oct 30, 2012 at 12:11
-
@Jake !! I didn't answer this for the bounty. The bounty reminded me that it was an open problem and one that there was considerable interest in seeing a solution. If you do something like that again I'll have to stop answering bountied questions. Commented Nov 4, 2012 at 20:07
-
@Jake, you are very generous. I think both Andrew and I didn't reply just for the bounty, but because the challenge was very interesting. So if you didn't assign it yesterday, it would have been the same to me. Thanks.– LuigiCommented Nov 4, 2012 at 20:15
-
@Jake, as you can see, Andrew and I are on the same wavelength: I started writing before reading Andrew's comment.– LuigiCommented Nov 4, 2012 at 20:18
I feel your pain there. The regular arrow head is almost invisible.
You can declare your own arrow head using \pgfarrowsdeclare
. You can modify the example below using commands from chapters 71 and 74 of the pgf manual. This is a simpler version of the example from chapter 74, which I latexified a bit while I was at it. Hope that helps. The idea behind declaring your own length is that it's going to scale with line thickness when you do it this way.
\newlength{\arrowsize}
\pgfarrowsdeclare{biggertip}{biggertip}{
\setlength{\arrowsize}{0.4pt}
\addtolength{\arrowsize}{.5\pgflinewidth}
\pgfarrowsrightextend{0}
\pgfarrowsleftextend{-5\arrowsize}
}{
\setlength{\arrowsize}{0.4pt}
\addtolength{\arrowsize}{.5\pgflinewidth}
\pgfpathmoveto{\pgfpoint{-5\arrowsize}{4\arrowsize}}
\pgfpathlineto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{-5\arrowsize}{-4\arrowsize}}
\pgfusepathqstroke
}
To use your arrow afterwards, say something like
\draw[-biggertip] (0,0) -- (0,1);
-
A useful hint could be, to take "arrows" out of the \usetikzlibrary statement. At least that did the trick for me.– ExocomCommented Sep 14, 2016 at 10:02