# TikZ set node label position more precisely

This seems like it should be really easy but I can't seem to find it anywhere...

I'd like to be able to fine-tune the positioning of a node label.

I'm aware of the \node[label=above/below/etc:{label}] (x) {}; syntax, but that doesn't seem to give you many options on where the label goes. I'd like to be able to place the label slightly closer or farther away, or maybe in a direction other than the 8 presets available.

\tikz[label distance=x] isn't a good solution because I need it to be node-specific.

You can define the direction of the label by using label=<angle>:<label text>. To specify the distance on a per node distance, you have to supply it to the label options: label={[label distance=<distance>]<angle>:<label text>}

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
every node/.style=draw,
every label/.style=draw
]
\node [label={[label distance=1cm]30:label}] {Node};
\end{tikzpicture}
\end{document}

• This is perfect, thanks. Does the label text need to be in braces? I found mine did, but that may have been because I was specifying color and size options. – Trevor Jun 7 '12 at 8:44
• They only need to be in braces if you supply options using [...], because you need to mask the [ and ]. If you're only supplying angle and text, you can just use label=20:text. – Jake Jun 7 '12 at 8:47
• @StrawberryFieldsForever: It's zero, the gap between the node contents only comes from the inner sep and outer sep of the node and label node. You can see this using \node [draw, label={[draw]above:Top}] {Bottom};, for example. – Jake Aug 2 '13 at 4:31
• @Jake Is there a way to add a connecting line between the node and the line? This could be helpful in crammed circumstances to make it clear which label belongs to which node. – Casimir Apr 15 '16 at 9:08
• @Casimir: Sure, that's what pin is for: pin={[pin distance=1cm]30:label} – Jake Apr 15 '16 at 9:11

Good to know all the other ways to do this, but I have always used xshift=<length>, and yshift=<length> to move a node or label.

The blue is the default, and the red is with the option [xshift=1.0cm, yshift=0.3cm], and the green (as suggested by percusse) is using an alternate syntax to specify the x and y shift as a vector [shift={(1.0,0.3)}].

## Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[blue]
\node [label={Label}] {Node};
\end{tikzpicture}
\begin{tikzpicture}[red]
\node [label={[xshift=1.0cm, yshift=0.3cm]Label}] {Node};
\end{tikzpicture}
\begin{tikzpicture}[green]
\node [label={[shift={(1.0,0.3)}]Label}] {Node};
\end{tikzpicture}
\end{document}

• The shift={(1,0.3}} syntax might also be included if you wish. – percusse Jun 7 '12 at 20:04
• @percusse: Thanks have updated the solution to include the alternate syntax. – Peter Grill Jun 7 '12 at 20:10
• Where can I find the documentation for how the default (blue) label position is determined? – A.Ellett Sep 7 '13 at 18:29
• @A.Ellett: I assume it is documented in the TikZ/PGF documentation. Perhaps you should post a new question on this. – Peter Grill Sep 9 '13 at 4:07

The simplest way is to use another node. Like you wrote, the label is a node "label". In \path ... node[⟨options⟩](⟨name⟩)at(⟨coordinate⟩){⟨text⟩} ...;the real label is ⟨text⟩. Now it's easy to add a node and a new label without the label option.

  \documentclass{scrartcl}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node [draw,circle ] (a) { Real label};
\node  at (a.60) {$\bullet$};
\node [draw] at ([shift={(95:1)}]a.60) {Second label};

\end{tikzpicture}

\end{document}


The only problem is that you need to give the name first node but you can do what you want. In the first version of TikZ, without the label option it was the only way.

• Shouldn't that be a comma: ={(95,1)} instead of a semicolon: ={(95:1)}? – sdaau Mar 19 '14 at 22:50
• The colon in (95:1) signifies that polar coordinates are being used. In this case it means that the point is at an angle of 95° and a distance of 1(cm) from the origin. See also: What does the colon in Tikz coordinates mean? – Sr. Schneider Aug 9 '16 at 10:07

The library "positioning" allows easy positioning of nodes with each other

La librairie "positioning" permet un positionnement facile et rapide des noeuds les uns par rapport aux autres

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
every node/.style=draw,
every label/.style=draw
]
\node (node) {Node};
\foreach \xx/\yy in {1/2,-1/3,5/0,-3/-2,0/0}{
\node [above right = \xx cm and \yy cm of node](label){Label\xx\yy};
}
\end{tikzpicture}
\end{document}


[fr] je complète la réponse pour répondre pour préciser le positionnement d'un label et pas seulement d'un noeud

[en] I complete the answer to answer to clarify the positioning of a label and not just a node

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
every node/.style=draw,
every label/.style=draw
]
\foreach \xx/\yy in {1/2,-1/3,5/0,-3/-2,0/0}{
\node [label={[above right = \xx cm and \yy cm of node]:label\xx\yy![enter image description here][2]}] (node) {Node};
}
\end{tikzpicture}
\end{document}


[fr] on remarque que l'origine du positionnement n'est pas le même que pour les noeuds

[en] we note that the origin of the Positioning is not the same as for nodes

• This is about node positioning, whereas my question pertained to label positioning – Trevor Jun 7 '12 at 8:45
• I completed the answer with positioning – rpapa Jun 7 '12 at 19:22

This pattern is also quite useful:

\node at ($(R) + (0.03,0.4)$)    {Your label!};


This way you can position the label relative to the coordinates of R.

Note that you need \usetikzlibrary{calc} for this way.

A similar solution that does not require calc (thanks Paul Gaborit!) is

\path (R) ++(0.03,0.4) node {Your label!};

• Without calc: \path (R) ++(0.03,0.4) node {Your label!}; – Paul Gaborit Feb 20 '14 at 17:24