4

Say I drew an arrow as

\draw [thick, ->] (0,0) -- ++(2, 0);

and now I want to give that arrow a label, $v$, at its tip using a node as

\draw [thick, ->] (0,0) -- ++(2, 0) node[right]{$v$};

This works perfectly well; however, I have also seen the use of "anchors" which have a similar effect

\draw [thick, ->] (0,0) -- ++(2, 0) node[anchor=west]{$v$};

It isn't clear to me what this anchor solution is doing differently than the first solution. It also doesn't make sense to me why "west" puts the anchor on the right... west is to the left not the right.

1
  • quite right -- the anchor is created to the left of v -- now try anchor=south and anchor = north see where the anchor is created with reference to v
    – js bibra
    Mar 14, 2021 at 4:09

1 Answer 1

9

The purpose of the anchor is that if you say

\path (x,y) node[anchor=<anchor>]{...};

then the anchor <anchor> of the node is at the point (x,y). These anchors can be directions like west, angles, i.e. numbers, and things like base. In the way you use anchor=west and right, they do have the same effect. To see this, let us look up the options in tikz.code.tex.

\tikzoption{anchor}{\def\tikz@anchor{#1}\let\tikz@do@auto@anchor=\relax}%

\tikzoption{right}[]{\def\tikz@anchor{west}\tikz@possibly@transform{x}{}{#1}}%

As you can see, if you use right without an argument, it is equivalent to anchor=west. The difference is that you can give right an argument, a distance that indicates how far right the node will be.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[font=\ttfamily]
 \path (0,2) node[anchor=west]{anchor=west} 
  (0,1) node[right]{right} 
  (0,0) node[right=1cm]{right=1cm} ;
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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