[Tex/LaTex] multiline label for node

nodestikz-pgf

Is there way of producing multiline label for node:

\node[label=below:{unit\\cell}]  (one){\tikz{\draw (0,0)rectangle (1,1);}};

The example produces "wrong" label output: untitcell

However, following code:

\node (one){\tikz{\draw (0,0)rectangle (1,1);}};
\path (one) node [below,align=center] {unit\\cell};

produces correct doble-line label, but alas wrong positioning…

Best Answer

Don't nest TikZ pictures (unless you really have to), it has some nontrivial consequences. Labels are also nodes(almost) only placed differently. If you add draw option to your node, you don't need to draw it's box additionally.

You can also pass regular options to the label node (because it's a node) as follows

\begin{tikzpicture}
\node[draw,minimum size=1cm,label={[align=center]below:unit\\cell}] (one){};
\end{tikzpicture}

enter image description here

If it becomes tedious to write complicated label codes just use the positioning syntax

\begin{tikzpicture}
\node[draw,minimum size=1cm] (one){};
\node[align=center,anchor=north] (lab) at (one.south) {unit\\cell};
\end{tikzpicture}

which leads to the same result. There are a few more ways of doing it but no need to complicate it for this simple application. You can find many examples here too by searching for positioning library use.