Tell me more ×
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 may 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

4 Answers

up vote 15 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

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

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

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

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.