Just like in any node, you need to specify the alignment in order to break the line.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [
matrix of nodes,
nodes={align=left, text width=3cm} % New!
] {
{some text} &
{text with \\ linebreak} \\
{other text} &
{more text} \\
};
\end{tikzpicture}
\end{document}
For some reason, for a node in a matrix, you also need to specify the width of the node text.
Any value larger than the actual width should work, but when finalizing your document, you should try to get the value as close as possible to the actual width of the text, so that the node anchors stand where they are expected to.
--- Edit ---
If one wants to avoid the text width specification, it is possible to draw the node manually:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [
matrix of nodes%,
%nodes={align=left, text width=3cm} % Not needed now
] {
{some text} &
\node[align=left] {text with \\ linebreak}; \\
{other text} &
{more text} \\
};
\end{tikzpicture}
\end{document}
text width. I would like to break lines only using explicit line breaks and let the dimensions of the nodes be automatically fixed otherwise. – M. Toya Nov 18 '15 at 14:47;)As far as I know, there is no easy way to get rid of thetext widthoption. If I remember correctly, the reason for this option is that a node with a line break is implemented as aminipage, and this requires setting the width explicitely. However, if you aren't interested in doing that in a matrix cell, you can use two nodes aligned in a matrix to emulate the linebreak behavior. – T. Verron Nov 18 '15 at 15:16nodes={align=center}– percusse Nov 19 '15 at 00:32(m-3-5)break, would they? – Symbol 1 Nov 19 '15 at 01:00align=centerand no text width specification. – T. Verron Nov 19 '15 at 07:15text widthto a large value andalignthe text at center, the text will be at the center but the node is still large. Therefore anchors like(X.south east)would be far away from the expected position. (In case of matrix, it would first produce an even larger matrix... so my comment did not make sense) – Symbol 1 Nov 19 '15 at 07:23alignwithout text width should be enough. If you look at the revisions of my answer, you'll see that I used to believe that too, back in may 2013. However, apparently it was no longer the case in sept. 2013, if it ever was (it was long ago... I think I tested before posting, but...) It seems that you tested it back in july 2013 as well, based on the comments in the linked thread. Do you know what changed exactly in summer 2013 on this matter? – T. Verron Nov 19 '15 at 13:58alignis enough for a node, not for a matrix cell. --- And reading back the whole conversation, I guess that it is what you meant from the start. Sorry! – T. Verron Nov 19 '15 at 14:03