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

  • [text width=1cm] but the question is not precise. You want multilines but where ... why \tikz{\draw (0,0)rectangle (1,1);}? – Alain Matthes Mar 24 '13 at 4:39

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

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

enter image description here

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

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

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.

  • Thank you for the answer! Well, I really have to, because instead of rectangle there is a more or less complex structure drawn. – Iohann Mar 24 '13 at 12:26
  • @percusse When I execute your code, I obtain the square but with 'unitcell' on one line. MWE: \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes,arrows,positioning} \tikzset{block/.style={draw,fill=blue!20,rectangle,minimum height=2em,minimum width=4em},sum/.style={draw,fill=blue!20,circle,node distance=1cm},input/.style={coordinate},output/.style={coordinate},pinstyle/.sty‌​le={pin edge={to-,thin,black}}} \begin{document} \begin{tikzpicture} \node[draw,minimum size=1cm](one){}; \node[align=center,anchor=north](lab) at (one.south) {unit\\cell}; \end{tikzpicture} \end{document} – Karlo Mar 26 '15 at 23:04
  • 1
    @MWijnand I get the linebroken version. Are you sure you have align=center? – percusse Mar 27 '15 at 12:08
  • @percusse Apparently, following error message shows up: Package pgfkeys Error: I do not know the key '/tikz/align' and I am going to ignore it. Perhaps you misspelled it. – Karlo Apr 3 '15 at 13:29

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.