Before I use the matrix facility. I can wrap text inside a box simply by specifying the align=left property then \\

However, in the matrix context, this seems not working. I want the graph like this

However the following code compiles fail on This is \\ node D under matrix

\documentclass[border=5mm, convert]{standalone}
\usetikzlibrary{shapes, positioning, matrix}

    \tikzset{myrect/.style={rectangle, rounded corners, align=left, minimum width=3cm, minimum height=1cm, draw=black}}

    \node [myrect] (a) {This is node A};
    \node [myrect, below = of a] (b) {This is \\ node B};

    \matrix (matrix1) [below = of b, nodes = {myrect}, matrix of nodes, row sep=1cm] {
        This is node C \\
        {This is \\ node D} \\

The line wrapping under matrix only works when I am adding things like text width = 3cm, but this seems redundant to align=left.

Can anyone help me out?

  • 2
    Do you really want a matrix or by chance a chain? – user121799 Jul 30 '18 at 6:35
  • I need to draw flowchart for some algorithms. Sometimes multi row and multi column to illustrate different code execution path. This is why I use the matrix. – Eric Sun Jul 30 '18 at 6:43
  • Hmmh, even then I am not 100% sure a matrix is the best choice (but your question is good regardless of that, that's why I upvoted it). – user121799 Jul 30 '18 at 6:45
  • Yeah, if there is alternative way to do so that will be also great :) – Eric Sun Jul 30 '18 at 6:48
  • 1
    Well, the question is to do what. What kind of flowchart do you need? In general, positioning, which you load and use is already a good choice IMHO, and chains can be helpful, too. (Again, the question by itself is interesting, and as of now I don't have a good answer. OK, that does not mean much, maybe @percusse will solve it ;-) – user121799 Jul 30 '18 at 6:49
\matrix (matrix1) [below = of b, nodes = {myrect}, matrix of nodes, row sep=1cm] {
    This is node C \\
    \shortstack{This is \\ node D}\\};

enter image description here

| improve this answer | |
  • this works except the text align changed from left to center. – Eric Sun Jul 30 '18 at 7:48
  • 1
    use \shortstack[l]{...} – user2478 Jul 30 '18 at 7:59
  • Thank you @Herbert. Seems I can remove the align=left when defining the myrect style – Eric Sun Jul 30 '18 at 8:03

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.