4

I'm working with Tikz package and I want to create a new arrow tip. So I used the following code which I found in internet:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

% Code for the new arrow tip, called halfcirc.
\pgfarrowsdeclare{halfcirc}{halfcirc}
{
\arrowsize=0.2pt
\advance\arrowsize by .5\pgflinewidth
\pgfarrowsleftextend{-4\arrowsize-.5\pgflinewidth}
\pgfarrowsrightextend{.5\pgflinewidth}
}
{
\arrowsize=0.2pt
\advance\arrowsize by .5\pgflinewidth
\pgfsetdash{}{0pt} % do not dash
\pgfsetroundjoin % fix join
\pgfsetroundcap % fix cap
\pgfpathmoveto{\pgfpoint{-4\arrowsize}{4\arrowsize}}
\pgfpatharc{90}{-90}{4\arrowsize}
\pgfusepathqstroke
}

% Declare a reversed version called revhalfcirc.
\pgfarrowsdeclarereversed{revhalfcirc}{revhalfcirc}{halfcirc}{halfcirc}

% Demonstration of the arrow tip.
\begin{tikzpicture}
\draw[help lines] (-3,-2) grid (3,2);
\draw[line width=10pt, revhalfcirc-halfcirc] (-2,0) -- (0,0);
\end{tikzpicture}

\end{document}

But an error pops up:

! Undefined control sequence.
\pgf@arrow@right@revhalfcirc -> \arrowsize 
                                           =0.2pt \advance \arrowsize by .5\...
l.32 ...pt, revhalfcirc-halfcirc] (-2,0) -- (0,0);

? 

What is the problem? I am a beginner in using Tikz.

Matteo
  • 41

1 Answers1

6

You need to load the tikz library providing support for arrows and such, by adding

\usetikzlibrary{arrows}

just below your call to the tikz package. This library then provides the \arrowsize command and others.

In your example, the code should look like :

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

% Code for the new arrow tip, called halfcirc.
\pgfarrowsdeclare{halfcirc}{halfcirc}
{
\arrowsize=0.2pt
\advance\arrowsize by .5\pgflinewidth
\pgfarrowsleftextend{-4\arrowsize-.5\pgflinewidth}
\pgfarrowsrightextend{.5\pgflinewidth}
}
{
\arrowsize=0.2pt
\advance\arrowsize by .5\pgflinewidth
\pgfsetdash{}{0pt} % do not dash
\pgfsetroundjoin % fix join
\pgfsetroundcap % fix cap
\pgfpathmoveto{\pgfpoint{-4\arrowsize}{4\arrowsize}}
\pgfpatharc{90}{-90}{4\arrowsize}
\pgfusepathqstroke
}

% Declare a reversed version called revhalfcirc.
\pgfarrowsdeclarereversed{revhalfcirc}{revhalfcirc}{halfcirc}{halfcirc}

% Demonstration of the arrow tip.
\begin{tikzpicture}
\draw[help lines] (-3,-2) grid (3,2);
\draw[line width=10pt, revhalfcirc-halfcirc] (-2,0) -- (0,0);
\end{tikzpicture}

\end{document}

Compiled, it gives the following output, which seems to be what you expect : Output

T. Verron
  • 13,552
  • Hello! Thanks for the reply. I still get the same error:

    ! Undefined control sequence.\pgf@arrow@right@revhalfcirc -> \arrowsize =0.2pt \advance \arrowsize by .5... l.32 ...pt, revhalfcirc-halfcirc] (-2,0) -- (0,0);

    ?

    I don't get why..

    – Matteo Sep 24 '12 at 14:22
  • That's strange, I tried it before posting and it worked like a charm. Could you update your MWE so that we can see what's going on? – T. Verron Sep 24 '12 at 14:24
  • Sure I am trying to write it in code format – Matteo Sep 24 '12 at 14:36
  • You can always edit your first question to add such precisions. – T. Verron Sep 24 '12 at 14:41
  • I can t manage to copy it, but it is exactly the same as I wrote above, but adding \usetikzlibrary{arrows} just below \usepackage{tikz} – Matteo Sep 24 '12 at 14:47
  • I don't know what to say. I posted my full code above, maybe you can try copy/pasting it to see if it compiles. Also, make sure you don't forget to save before compiling, that's an easy mistake. – T. Verron Sep 24 '12 at 14:49
  • I really don't know, maybe the package I installed is corrupted or something. I saved before compiling but still get the same error. Anyway, thank you very much! – Matteo Sep 24 '12 at 14:57