4

The following code block contains a minimal working example. The first TikZ drawing doesn't use explicitly defined nodes. The second TikZ drawing uses explicitly defined nodes.

I thought that these two drawings would produce the same result, because in both drawings the nodes don't have labels. However, I noticed that the length of the edges is different. (see image below).

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \draw[->] (0,0) -- (1,0);
  \draw[->] (0,0.2) -- (1,0.2);
  \draw[->] (0,0.4) -- (1,0.4);
\end{tikzpicture}

\begin{tikzpicture}
  \node (start1) at (0,0)   {};
  \node (end1)   at (1,0)   {};
  \node (start2) at (0,0.2) {};
  \node (end2)   at (1,0.2) {};
  \node (start3) at (0,0.4) {};
  \node (end3)   at (1,0.4) {};
  \draw[->] (start1) -- (end1);
  \draw[->] (start2) -- (end2);
  \draw[->] (start3) -- (end3);
\end{tikzpicture}

\end{document}

\end{document}

enter image description here

1
  • In addition to the answers, you might want to know that that the amount of (extra) space inside a (non-)empty node is called inner sep and is initially .3333em. Commented Feb 25 at 10:54

2 Answers 2

6

Perhaps you want coordinates instead of nodes. Nodes even when empty have a size (unless you select the origin of the arrow to an anchor, the oposite of where you are anchoring the node itself)

See the following MWE with coordinates instead:

\documentclass{article}
\usepackage{tikz}

\begin{document}
    
    \begin{tikzpicture}
        \draw[->] (0,0) -- (1,0);
        \draw[->] (0,0.2) -- (1,0.2);
        \draw[->] (0,0.4) -- (1,0.4);
    \end{tikzpicture}
    
    \vspace{2ex}
    
    \begin{tikzpicture}
        \coordinate (start1) at (0,0);
        \coordinate (end1)   at (1,0);
        \coordinate (start2) at (0,0.2);
        \coordinate (end2)   at (1,0.2);
        \coordinate (start3) at (0,0.4);
        \coordinate (end3)   at (1,0.4);
        \draw[->] (start1) -- (end1);
        \draw[->] (start2) -- (end2);
        \draw[->] (start3) -- (end3);
    \end{tikzpicture}
    
\end{document}

enter image description here

2

This is just to illustrate what @Mane32 says about the size of nodes and anchors.

To the left, the option draw makes the outline of the nodes visible. As you can see, the arrows start and stop at the border of the nodes.

To the right, the arrows start and stop at the center anchor of the nodes. Now the arrows have the same length as with the explicit \draw commands.

enter image description here

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \draw[->] (0,0) -- (1,0);
  \draw[->] (0,0.2) -- (1,0.2);
  \draw[->] (0,0.4) -- (1,0.4);
  \begin{scope}[yshift=-6mm]
    \node[draw] (start1) at (0,0)   {};
    \node[draw] (end1)   at (1,0)   {};
    \node[draw] (start2) at (0,0.2) {};
    \node[draw] (end2)   at (1,0.2) {};
    \node[draw] (start3) at (0,0.4) {};
    \node[draw] (end3)   at (1,0.4) {};
    \draw[->] (start1) -- (end1);
    \draw[->] (start2) -- (end2);
    \draw[->] (start3) -- (end3);
  \end{scope}
\end{tikzpicture}
\quad
\begin{tikzpicture}
  \draw[->] (0,0) -- (1,0);
  \draw[->] (0,0.2) -- (1,0.2);
  \draw[->] (0,0.4) -- (1,0.4);
  \begin{scope}[yshift=-6mm]
    \node[draw] (start1) at (0,0)   {};
    \node[draw] (end1)   at (1,0)   {};
    \node[draw] (start2) at (0,0.2) {};
    \node[draw] (end2)   at (1,0.2) {};
    \node[draw] (start3) at (0,0.4) {};
    \node[draw] (end3)   at (1,0.4) {};
    \draw[->] (start1.center) -- (end1.center);
    \draw[->] (start2.center) -- (end2.center);
    \draw[->] (start3.center) -- (end3.center);
  \end{scope}
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .