6

I ran into this problem when using draw with a predefined command. Any idea how to fix? Here's a minimal (not) working example:

\documentclass{article}
\usepackage{tikz}

\newcommand{\Ve}{(1,1)}
\begin{document}
    \begin{tikzpicture}
        \draw (1,0) to[bend right] (1,1) ; %works
        \draw   \Ve to[bend right] (1,0) ; %works
        \draw (1,0) to[bend right] \Ve ;   %doesn't work
    \end{tikzpicture}
\end{document}

The error produced:

Latex Error: ./untitled.tex:9 Package tikz Error: (, +, coordinate, pic, or node expected. Latex Error: ./untitled.tex:9 Package pgf Error: No shape named is known.

  • 5
    You could use coordinate like this: \begin{tikzpicture} \coordinate (VE) at (1,1); \draw (1,0) to[bend right] (1,1) ; \draw (VE) to[bend right] (1,0) ; \draw (1,0) to[bend right] (VE) ; \end{tikzpicture} – Bobyandbob Jun 29 '17 at 18:55
  • @Bobyandbob that answers my question as far as I'm concerned – Bjørn Kjos-Hanssen Jun 29 '17 at 19:08
  • 2
    @BjørnKjos-Hanssen Although the coordinate way is the cleanest and preferred way, you may be interested in that defining \Ve without parenthesis; that is, \newcommand{\Ve}{1,1}; and then using (\Ve) instead of \Ve, also works. – JLDiaz Jun 29 '17 at 19:31
  • The first one will work with \expandafter\draw \Ve but the second would be more complex and this approach is not to be recommended. – cfr Jun 29 '17 at 22:59
5

You need parentheses. With \draw the path, which is specified with for example two points should be drawn. The coordinates of the start and end positions are specified as points in round brackets. [See: 2.3 Straight Path Construction,p.31]

Definition: point position

  • in cm: (1,0) and (1,1)

    The positions are specified within a special coordinate system in which, initially, one unit is 1cm. [See 2.2.1 Setting up the Environment in LATEX p.29-30]

  • in pt: (1pt,0pt) and (1pt,1pt) -> The positions are specified within a special coordinate system with unitpt.
  • in polar coordinates: (0:1) and (45:{sqrt(2)})-> polar coordinates: 1 respectively sqrt(2) (as radius) in direction 0 respectively 45 degree (angle). To calculate {sqrt(2)} (to get the correct radius) you need \usetikzlibrary{calc}.See 2.15 Specifying Coordinates,p37ff.
  • with macro: (\Va) and (\Ve) -> TikZ parser understands coordinates and nodes(and their names) by explicitly looking for ( character in the input stream. Hence if brackets are hidden inside the macro, the parser first fail to find the bracket and will then expand the macro which will be too late. Instead define your own commands with \newcommand{\Va}{1,0} and \newcommand{\Ve}{1,1} ( hint from @JLDiaz comment)

But i prefer and recommend:

  • with coordinates: (A) and (B) -> Defining two coordinates (name: A, B) using the \coordinate command. For example \coordinate (A) at (1,0); and \coordinate (B) at (1,1);

Solution:

enter image description here

MWE:

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc}
%\newcommand{\Ve}{1,1}
\begin{document}
    \begin{tikzpicture}
    \coordinate (VE) at (1,1);
   %\coordinate (VE) at (45:{sqrt(2)});
        \draw (1,0) to[bend right] (1,1);
        \draw   (VE) to[bend right] (1,0);
        \draw (1,0) to[bend right] (VE) ;
    \end{tikzpicture}
%    \begin{tikzpicture}
%        \draw (1,0) to[bend right] (1,1);
%        \draw (\Ve) to[bend right] (1,0);
%        \draw (1,0) to[bend right] (\Ve) ;
%    \end{tikzpicture}
\end{document}

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.