# How can the distance from a TikZ node to its label be changed?

I have a diagram of a few nodes and a few labels. I want the distance of each label from its respective node to be increased (to prevent it from overlapping with lines of the diagram). What is the correct syntax to do this?

\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (0,0) grid (5,1);
\node[label=above:\rotatebox{-45}{king} ] at (0.5,0.5) {0};
\node[label=above:\rotatebox{-45}{queen}] at (1.5,0.5) {1};
\node[label=above:\rotatebox{-45}{man}  ] at (2.5,0.5) {0};
\node[label=above:\rotatebox{-45}{woman}] at (3.5,0.5) {0};
\node[label=above:\rotatebox{-45}{child}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}


Setting label distance I think.

\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[label distance=5mm]
\draw[step=1cm] (0,0) grid (5,1);
\node[label=above:\rotatebox{-45}{king} ] at (0.5,0.5) {0};
\node[label={[label distance=1cm]above:\rotatebox{-45}{queen}}] at (1.5,0.5) {1};
\node[label=above:\rotatebox{-45}{man}  ] at (2.5,0.5) {0};
\node[label=above:\rotatebox{-45}{woman}] at (3.5,0.5) {0};
\node[label=above:\rotatebox{-45}{child}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}


• Ah, that's very useful. Do you know how the distance could be set for each label? For example, how could the label for "queen" be raised a bit higher than the others? Mar 2 '17 at 12:22
• @BlandCorporation See updated answer. (Note also the every label stuff wasn't necessary. Mar 2 '17 at 12:25
• Hey, thank you very much for your solution on that. Mar 2 '17 at 15:02

You can place the labels with numbers(for example 90 instead of above) and add a distance. With adding label distance=<...> like this:

\node[label={[label distance=2mm]90:\rotatebox{-45}{king}}]

-> 3.9 Adding Labels Next to Nodes (p.52) it says: number instead of things like below left -> 17.10.2 The Label option label (p.340) : The is additionally inserted between the main node and the label node.

MWE:

\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (0,0) grid (5,1);
\node[label={[label distance=2mm]90:\rotatebox{-45}{king}}] at (0.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{queen}}] at (1.5,0.5) {1};
\node[label={[label distance=2mm]90:\rotatebox{-45}{man}}] at (2.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{woman}}] at (3.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{child}}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}

• Thank you very much for your solution and for your explanation of the syntax used for the labels. If I could accept two solutions, I would. Mar 2 '17 at 15:04