6

I am using the package hobby for the first time, and it seems to me that using named nodes instead of coordinates is not supported. In particular, why do the following MWEs produce two different pictures ?

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}

\begin{tikzpicture} \draw[help lines] (0,0) grid[step=0.25] (1,1); \draw (0,0) to [curve through={ (0.15,0.35) .. (0.5,0.5) .. (0.8,0.6) } ]
(1,1); \end{tikzpicture}

\begin{tikzpicture}

\node (n1) at (0,0) {}; \node (n2) at (0.15,0.35){}; \node (n3) at (0.5,0.5){}; \node (n4) at (0.8,0.6){}; \node (n5) at (1,1){};

\draw[help lines] (0,0) grid[step=0.25] (1,1); \draw (n1) to [curve through={ (n2) .. (n3) .. (n4) } ]
(n5); \end{tikzpicture} \end{document}

  • Sorry for the hideous formatting, I am very new in this forum ... – G. Fougeron Dec 26 '17 at 12:11
  • If you select your code and then click {} button above it in the editing mode, it marks it as a code block. Alternatively you can leave 4 whitespace characters manually. – percusse Dec 26 '17 at 12:23
  • The "nodes aren't coordinates" issue has caused quite a few questions on this site. percusse's explanation at https://tex.stackexchange.com/a/81854/86 is a good one to read in addition to Zarko's answer below. – Andrew Stacey Dec 26 '17 at 18:04

1 Answers1

6

nodes are not coordinates! they have non zero size, so the lines between them is discontinued. as work around you have two possibilities:

  • for named coordinates use for example

\draw
(n1.center) to [curve through={
(n2.center) ..
(n3.center)   ..
(n4.center) } ]
(n5.center);
  • or define named coordinates as

\coordinate (n1) at (0,0); 
\coordinate (n2) at (0.15,0.35); 
\coordinate (n3) at (0.5,0.5); 
\coordinate (n4) at (0.8,0.6); 
\coordinate (n5) at (1,1);

in both cases you will get the same result:

enter image description here

Zarko
  • 296,517
  • Amazing ! Exactly what I was looking for. I will study your "nodes are not coordinates!" remark :-). – G. Fougeron Dec 26 '17 at 13:27
  • @G.Fougeron Coordinates are nodes, though. So some nodes are coordinates. But default nodes are not coordinates. – cfr Dec 27 '17 at 01:32
  • 1
    Nodes can have zero size. \node [shape=coordinate] {};. – cfr Dec 27 '17 at 01:32
  • May I know what the actual length units are used by default in (0.15,0.35), for example? – Diaa Dec 17 '23 at 04:43
  • default units in TikZ are centimeters, however by (0.15,0.35) you determine coordinate (point, which is 1.5cm right and 0.35cmm above from origin . what is there depends are you positioned there: coordinate or node. – Zarko Dec 17 '23 at 05:37