7

Since anchor cardinal points (north, south, etc) as options, I would expected they would reproduce what I usually see in a map (see Expected in the picture). That's note the case (see Real). Why does this happens? (I did look for an answer, but was not sure what do look for)

anchor cardinal options

Code:

\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}   
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
%---------------------------------- tikz ---------------------------------------
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc,arrows,patterns,external,shapes.callouts,graphs,decorations.pathreplacing,chains}
\usepackage{fixltx2e} 

\begin{document}

   \begin{tikzpicture}[thick,
      every node/.style={draw,diamond,minimum height=2cm,minimum width=2cm},
      ]

      \node[draw=none] at (0,3)  {Expected};

      \node[anchor=north] at (0,0) {S};
      \node[anchor=south] at (0,0) {N};
      \node[anchor=east] at (0,0) {W};
      \node[anchor=west] at (0,0) {E};


      \node[draw=none] at (5,3)  {Real};

      \node[draw,diamond,anchor=north] at (5,0) {N};
      \node[draw,diamond,anchor=south] at (5,0) {S};
      \node[draw,anchor=east] at (5,0) {E};
      \node[draw,anchor=west] at (5,0) {W};

    \end{tikzpicture}
\end{document}
9

It's a common source of confusion; perhaps this helps to clarify things:

\documentclass{article}    
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[fill] (0,0) circle (1.5pt);
\node[draw,text width=1cm,anchor=north] at (0,0) (rect) {};
\node[above] at (rect.north) {north};
\begin{scope}[xshift=2cm]
\draw[fill] (0,0) circle (1.5pt);
\node[draw,text width=1cm,anchor=south] at (0,0) (rect) {};
\node[below] at (rect.south) {south};
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

The north anchor is in the middle at the upper end of the shape. When you give the option anchor=north, the shape will be placed such that this northern anchor will lie on the specified position and thus the node is below the specified position.

On the other hand, the south anchor is in the middle at the lower end of the shape. When you give the option anchor=south, the shape will be placed such that this southern anchor will lie on the specified position and thus the node is above the specified position.

In fact, Till Tantau was aware that this would be a source of confusion; on page 43 of the manual one finds

However, Karl thinks that, though ``correct,'' it is quite counter-intuitive that in order to place something below a given point, he has to use the north anchor. For this reason, there is an option called below, which does the same as anchor=north. Similarly, above right does the same as anchor=south west.

6

Anchors are relative to the node that is being drawn. For example the line

\node[anchor=north] at (0,0) {S};

means: draw a node with text "S" and put its north anchor (the point at the top and horizontally centered) at coordinate (0,0). Therefore the text "S" is below or "south" with respect to the coordinate you specify. You must think about the position of the coordinate with respect to the node, not the position of the node with respect to the coordinate.

I don't know if this has made the picture clearer for you, but I hope so.

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.