5

What's the best way to specify a node position on a path? The ways I found are not equivalent, which bothers me.

Why is below right different to below, right and right, below? Why is below right different to below=1pt, right=1pt and right=1pt, below=1pt?

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below right] {curve1} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, right, below] {curve2} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below, right] {curve3} (20:6);
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to node [very near end, sloped, right=1pt, below=1pt] {curve1} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below=1pt, right=1pt] {curve2} (20:6);
\end{tikzpicture}

\end{document}

First image Second image

5
  • 4
    If I recall correctly, separated below and right will overwrite each other. – Symbol 1 May 10 '17 at 1:49
  • I want to give values to both below and right, but doing so causes an error. Is there a way to get around this problem? – Kurzd May 10 '17 at 1:53
  • 3
    Use the positioning library: \draw (0,0) to node [below right=5pt and 100pt] {n} (1,1);. You are using deprecated syntax. – cfr May 10 '17 at 2:00
  • @cfr Is below, right the deprecated syntax you mention? – Kurzd May 10 '17 at 6:12
  • 1
    Sorry. I was confused when I wrote that. In any case, no, that's never been supported that I know of. (But I don't know the history.) It is really below of= etc. which is considered deprecated, I think. The recommended syntax is below=<dim> of. But that's not relevant here. – cfr May 10 '17 at 14:49
2

Everything about positioning and anchors is explained in section 17.5 Positioning nodes and it's worth to read it.

In any case I'll try to gave you some basic ideas about it.

The first and most important lesson is that any positioning command determines the node's anchor to be used. If you write below, what will be placed below this position will be the north anchor, and if you write above right, the anchor selected will be south east. (You can change this behaviour selecting a different anchor after the positioning option)

Second lesson, only the last positioning option survives. If you write below, right (with , between them) only right will be applied.

As an example:

\draw (0,0) [out=40, in=150] to 
node [pos=0, draw, sloped, above left] (al) {above left}
node [pos=0, draw, sloped, below right] {below right} 
node [pos=.5, draw, sloped, right, below] (rb) {right, below}
node [pos=1, draw, sloped, below, right] (br) {below, right}
(20:6);

will produce

enter image description here

Third lesson: when using new positioning library with explicit distance values like above=2mm, expressions like above right=2mm and above right=2mm and 2mm produce different results.

As an example, following code:

\draw (0,0) [out=40, in=150] to coordinate[pos=.5] (aux)
    node [pos=.5, draw, sloped, below right=3pt] {below right} 
    node [pos=.5, draw, sloped, above left=3pt] {above left} 
    node [pos=.5, draw, sloped, above right=3pt and 3pt] {above right} 
    node [pos=.5, draw, sloped, below left=3pt and 7pt] {below left} 
    (20:6);

generates

enter image description here

Of course, everything is much more better explained in previous link.

The complete code for previous examples is

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to 
node [pos=0, draw, sloped, above left] (al) {above left}
node [pos=0, draw, sloped, below right] {below right} 
node [pos=.5, draw, sloped, right, below] (rb) {right, below}
node [pos=1, draw, sloped, below, right] (br) {below, right}
(20:6);

\fill[red] (al.south east) circle(1pt);
\fill[red] (rb.north) circle(1pt);
\fill[red] (br.west) circle(1pt);

\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to coordinate[pos=.5] (aux)
    node [pos=.5, draw, sloped, below right=3pt] {below right} 
    node [pos=.5, draw, sloped, above left=3pt] {above left} 
    node [pos=.5, draw, sloped, above right=3pt and 3pt] {above right} 
    node [pos=.5, draw, sloped, below left=3pt and 7pt] {below left} 
    (20:6);
\fill[red] (aux) circle(1pt);
\end{tikzpicture}

\end{document}

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.