10

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

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}

enter image description here

  • 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? – BlandCorporation Mar 2 '17 at 12:22
  • @BlandCorporation See updated answer. (Note also the every label stuff wasn't necessary. – Torbjørn T. Mar 2 '17 at 12:25
  • Hey, thank you very much for your solution on that. – BlandCorporation Mar 2 '17 at 15:02
2

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

See: Tikz manual http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/ctan/graphics/pgf/base/doc/pgfmanual.pdf

-> 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.

enter image description here

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. – BlandCorporation Mar 2 '17 at 15:04

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.