1

Something confuses me when I draw a line with some label in the middle.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\draw (0,0) -- node[below] {a} ++ (4,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw (-2,0) -- node[below] {a} ++ (2,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw (-2,0) -- (2,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw (2,0) -- node[below] {a} ++ (0,0);
\end{tikzpicture}

\end{document}

The following is what I got. Here are my questions:

  • I can understand the first one, a line of length 4 with label in the middle.
  • Why the second one is only half the length of the first one?
  • In the third one, if I didn't add the label, why is the length the same as the first one?
  • Why is there no line in the last one?
  • One last question, what does -- and ++ mean?

enter image description here

1

The ++ provides a relative coordinate with respect to the last point. So. ++(2,0) means, roughly, move 2 rightwards and 0 up/down.

Hence, (0,0) ++(2,0) gives a path from the origin to (2,0) but (-2,0) ++(2,0) gives a path from (-2,0) to the origin. Similarly (43.5,6.78) ++(2,0) gives a path from (43.5,6.78) to (45.5,6.78).

++(0,0), therefore means don't move at all either up/down or right/left.

The ++ also changes the position afterwards so that with (-2,0) ++(2,0), the last point is now at (0,0), for instance.

The label doesn't add to the length of the path: ++(4,0) is still just 4 to the right of the last point however many nodes are in between.

-- just means a line as the crow flies between points, which is drawn if we're drawing things at all.

\path (0,0) -- (2,0);

just moves in a straight line from the origin to (2,0).

 \draw (0,0) -- (2,0);

also draws that line, whereas

\draw (0,0) (2,0);

would simply move, without drawing, despite the \draw and

\draw (0,0) (2,0) -- (4,0);

would move from the origin to (2,0) and then draw a straight line from (2,0) to (4,0).

  • Thank you for the explanation. Now I understand \draw (-2,0) -- node[below] {a} ++ (2,0); will draw a line from (-2,0) to (0,0), but is it true that the node will be automatically in the middle between (-2,0) and (0,0)? – Patrick Li Jun 8 '16 at 11:26
  • Yes, it will automatically be placed in the middle by default. You can change it by saying e.g. node [below, near end] or node [below, pos=.3] or whatever, but midway is default. – cfr Jun 8 '16 at 12:07

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.