Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Similar problem: How can I force TikZ pin angle? –  Jake Jun 7 '12 at 8:04
    
I completed the answer with positioning –  rpapa Jun 7 '12 at 19:22

5 Answers 5

up vote 36 down vote accepted

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}
share|improve this answer
    
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
    
What is the default label distance if you only write above, below, right or left? –  StrawberryFieldsForever Aug 2 '13 at 4:06
1  
@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

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)}].

enter image description here

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}
share|improve this answer
    
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}    

enter image description here

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.

share|improve this answer
    
Shouldn't that be a comma: ={(95,1)} instead of a semicolon: ={(95:1)}? –  sdaau Mar 19 at 22:50

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}

enter image description here

[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}

enter image description here

[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

share|improve this answer
    
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!};
share|improve this answer
1  
Without calc: \path (R) ++(0.03,0.4) node {Your label!}; –  Paul Gaborit Feb 20 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.