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. – Alfred M. Nov 18 '15 at 14:47;)
As far as I know, there is no easy way to get rid of thetext width
option. 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 0:32(m-3-5)
break, would they? – Symbol 1 Nov 19 '15 at 1:00