5

Dear fellow LaTeX/TikZ users. I'm clearly misunderstanding something about how TikZ handles coordinate definitions. I am trying to draw a Bezier curve between prededfined points, but TikZ complains as soon as the target point is a defined coordinate (here (B)) instead of a literal coordinate (here (10,10)) the compile fails with the following error:

! Package PGF Math Error: Unknown function `up' (in 'up').

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
...                                              

l.16   \draw (A) to [out=down,in=up] (B)
;
? 

I tried to google this but can't seem to find this specific error. What am I doing wrong?

Here is a minimal working example:

\documentclass[]{article}

\usepackage{tikz}
% EDIT: This is for workaround
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,1);
  \coordinate (B) at (10,10);

  % This will work
  \draw (0,1) to [out=down,in=up] (10,10);
  % So will this
  \draw (A)   to [out=down,in=up] (10,10);  
  % And this
  \draw (A) -- (B);

  % But these wont
  % \draw (A) to [out=down,in=up] (B);
  % \draw (0,1) to [out=down,in=up] (B);

  % EDIT: Added the following workaround:
  \draw ($(A)$) to [out=down,in=up] ($(B)$);
\end{tikzpicture}
\end{document} 

EDIT

I found a workaround, but it made me even more confused. Using \tikzlibrary{calc} and replacing (B) with ($(B)$) removes the problem, but I don't understand why. The ($...$) enviroment for calc allows calculations for points, but how/why is ($(B)$) different from (B)?

6

The problem is that if you use a named coordinate (or a node) as target, tikz will use the in value as anchor. But there is no up anchor in a node. This means that in=90 (which will set a target B.90) or in=north (which will set a target B.north) will work, but not in=up as B.up doesn't exist.

Your work-around works as in this case the target is converted in an absolute coordinate (0.0pt,28.45274pt) and tikz doesn't try to use the in value as anchor.

\documentclass[]{article}

\usepackage{tikz}

\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,1);
  \coordinate (B) at (10,10);

  \draw (A) to [out=down,in=90] (B);
  \draw (A) to [out=down,in=north] (B);
  %won't work 
 % \draw (A) to [out=down,in=up] (B);

  \draw (A) to [out=down,in=up] ($(B)$);


\end{tikzpicture}
\end{document} 
  • Thank you! My general level confusion has turned into specific knowledge that I do not understand how anchors work or, to be honest, what anchors even are. The latter is much more actionable :) – Rami Luisto Feb 2 '18 at 18:07
  • 1
    Look in the documentation at chapter Shape Library. There you can see the various anchors. A coordinate is a bit special but things like "B.south" works there too. – Ulrike Fischer Feb 2 '18 at 18:16

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.