[Tex/LaTex] How to introduce a line break in a TikZ node label?

labelsnodestikz-pgf

I need to introduce line breaks into the label of a node. This is what I've tried so far, but none of it worked:

1:

\node[node, label={[split parts = 4]alpha \nodepart{two} bravo \nodepart{three} charlie nodepart{four} delta }, below of = 5] (8) {$8$};

2:

\node[node, label={alpha\\bravo\\charlie\\delta}] below of = 5] (8) {$8$};

3:

\node[node, label={alpha \newline bravo \newline charlie \newline delta}] below of = 5] (8) {$8$};

All of those approaches are fairly similar. I found solutions on line breaks inside nodes, and on labels on edges, but not in labels of nodes.

In fact, I've tried the suggestions I found on labels of nodes, but it didn't work as well.

Best Answer

A label is just like any other node, so you have to specify the align of the label before the manual line breaks work, using \node [label={[align=left]<label text\\with line breaks>}] {<node text>}. Alternatively (again, like with any other node), you can specify the text width of the label, that way manual line breaks will work and the text will wrap automatically after the specified text width.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node [draw, label={[align=left]First\\Second}] {Node};
\end{tikzpicture}
\end{document}
Related Question