Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I get a linebreak inside a matrix node? The following gives the error:

Package tikz Error: Giving up on this path. Did you forget a semicolon?.

unless I remove the linebreak.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
    \matrix (m) [
        matrix of nodes
    ] {
         {some text} &
         {this node \\ does not work} \\
         {other text} &
         {more text} \\
    };
\end{tikzpicture}
\end{document}
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
I still get ! Package tikz Error: Giving up on this path. Did you forget a semicolon?. when compiling your example, without any modification. What version of tikz or other is required for this to work? –  Georges Dupéron Sep 16 '13 at 11:55
    
Hmf. It doesn't work here either. I'm pretty sure I tested it back then, and I think the OP wouldn't have accepted it if it didn't work, but I also don't think I updated any tikz package since then. So no idea what's happening. Anyway, I'm adding a fix to the answer. Thanks for the notification! –  T. Verron Sep 16 '13 at 14:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.