Tikz Matrix: Nodes are not 'in-a-row'?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I am using a matrix for node-positioning with a fixed node witdh.
However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.



MWE which shows this behaviour:



documentclass[tikz]standalone
usetikzlibrarymatrix,fit
begindocument
begintikzpicture
matrix (m) [%
matrix of nodes,%
nodes in empty cells,%
nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
column sep=.5cm,%
row sep=.5cm,%
anchor=center
]%

&Two\line\breaks&One line&& \
One\linebreak&&&& \
&&&Two\line\break& \
&&One&& \
;
foreach row/rownext in 1/2,2/3,3/4,4/4

foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

draw(m-row-col) to (m-row-colnext);
draw(m-row-col) to (m-rownext-col);


endtikzpicture
enddocument


Picture or result:



enter image description here










share|improve this question

























    up vote
    4
    down vote

    favorite












    I am using a matrix for node-positioning with a fixed node witdh.
    However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.



    MWE which shows this behaviour:



    documentclass[tikz]standalone
    usetikzlibrarymatrix,fit
    begindocument
    begintikzpicture
    matrix (m) [%
    matrix of nodes,%
    nodes in empty cells,%
    nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
    column sep=.5cm,%
    row sep=.5cm,%
    anchor=center
    ]%

    &Two\line\breaks&One line&& \
    One\linebreak&&&& \
    &&&Two\line\break& \
    &&One&& \
    ;
    foreach row/rownext in 1/2,2/3,3/4,4/4

    foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

    draw(m-row-col) to (m-row-colnext);
    draw(m-row-col) to (m-rownext-col);


    endtikzpicture
    enddocument


    Picture or result:



    enter image description here










    share|improve this question























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I am using a matrix for node-positioning with a fixed node witdh.
      However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.



      MWE which shows this behaviour:



      documentclass[tikz]standalone
      usetikzlibrarymatrix,fit
      begindocument
      begintikzpicture
      matrix (m) [%
      matrix of nodes,%
      nodes in empty cells,%
      nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
      column sep=.5cm,%
      row sep=.5cm,%
      anchor=center
      ]%

      &Two\line\breaks&One line&& \
      One\linebreak&&&& \
      &&&Two\line\break& \
      &&One&& \
      ;
      foreach row/rownext in 1/2,2/3,3/4,4/4

      foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

      draw(m-row-col) to (m-row-colnext);
      draw(m-row-col) to (m-rownext-col);


      endtikzpicture
      enddocument


      Picture or result:



      enter image description here










      share|improve this question













      I am using a matrix for node-positioning with a fixed node witdh.
      However, as some nodes contaning more than one line of text some nodes are shifted in y-axis and I don't know why or how to fix this. There seems to be enough space inside the node in y-axis. I also connected some nodes which result in an ugly picture.



      MWE which shows this behaviour:



      documentclass[tikz]standalone
      usetikzlibrarymatrix,fit
      begindocument
      begintikzpicture
      matrix (m) [%
      matrix of nodes,%
      nodes in empty cells,%
      nodes=rectangle, draw ,align=center,minimum height=1.5cm, text width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm, fill=white,%
      column sep=.5cm,%
      row sep=.5cm,%
      anchor=center
      ]%

      &Two\line\breaks&One line&& \
      One\linebreak&&&& \
      &&&Two\line\break& \
      &&One&& \
      ;
      foreach row/rownext in 1/2,2/3,3/4,4/4

      foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

      draw(m-row-col) to (m-row-colnext);
      draw(m-row-col) to (m-rownext-col);


      endtikzpicture
      enddocument


      Picture or result:



      enter image description here







      tikz-pgf horizontal-alignment vertical-alignment matrices nodes






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      SRel

      43911




      43911




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You only need to add anchor=center to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.



          documentclass[tikz]standalone
          usetikzlibrarymatrix,fit
          begindocument
          begintikzpicture
          matrix (m) [%
          matrix of nodes,%
          nodes in empty cells,%
          nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
          width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
          fill=white,anchor=center,%
          column sep=.5cm,%
          row sep=.5cm,%
          anchor=center
          ]%

          & Two\ line \breaks & One line && \
          One\linebreak&&&& \
          &&&Two\line\breaks& \
          &&One&& \
          ;
          foreach row/rownext in 1/2,2/3,3/4,4/4

          foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

          draw(m-row-col) to (m-row-colnext);
          draw(m-row-col) to (m-rownext-col);


          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer




















          • I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
            – marmot
            3 hours ago










          • The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
            – Ignasi
            6 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f451528%2ftikz-matrix-nodes-are-not-in-a-row%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          You only need to add anchor=center to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.



          documentclass[tikz]standalone
          usetikzlibrarymatrix,fit
          begindocument
          begintikzpicture
          matrix (m) [%
          matrix of nodes,%
          nodes in empty cells,%
          nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
          width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
          fill=white,anchor=center,%
          column sep=.5cm,%
          row sep=.5cm,%
          anchor=center
          ]%

          & Two\ line \breaks & One line && \
          One\linebreak&&&& \
          &&&Two\line\breaks& \
          &&One&& \
          ;
          foreach row/rownext in 1/2,2/3,3/4,4/4

          foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

          draw(m-row-col) to (m-row-colnext);
          draw(m-row-col) to (m-rownext-col);


          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer




















          • I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
            – marmot
            3 hours ago










          • The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
            – Ignasi
            6 mins ago














          up vote
          4
          down vote



          accepted










          You only need to add anchor=center to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.



          documentclass[tikz]standalone
          usetikzlibrarymatrix,fit
          begindocument
          begintikzpicture
          matrix (m) [%
          matrix of nodes,%
          nodes in empty cells,%
          nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
          width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
          fill=white,anchor=center,%
          column sep=.5cm,%
          row sep=.5cm,%
          anchor=center
          ]%

          & Two\ line \breaks & One line && \
          One\linebreak&&&& \
          &&&Two\line\breaks& \
          &&One&& \
          ;
          foreach row/rownext in 1/2,2/3,3/4,4/4

          foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

          draw(m-row-col) to (m-row-colnext);
          draw(m-row-col) to (m-rownext-col);


          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer




















          • I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
            – marmot
            3 hours ago










          • The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
            – Ignasi
            6 mins ago












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          You only need to add anchor=center to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.



          documentclass[tikz]standalone
          usetikzlibrarymatrix,fit
          begindocument
          begintikzpicture
          matrix (m) [%
          matrix of nodes,%
          nodes in empty cells,%
          nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
          width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
          fill=white,anchor=center,%
          column sep=.5cm,%
          row sep=.5cm,%
          anchor=center
          ]%

          & Two\ line \breaks & One line && \
          One\linebreak&&&& \
          &&&Two\line\breaks& \
          &&One&& \
          ;
          foreach row/rownext in 1/2,2/3,3/4,4/4

          foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

          draw(m-row-col) to (m-row-colnext);
          draw(m-row-col) to (m-rownext-col);


          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer












          You only need to add anchor=center to the nodes. You only added this option to the matrix (node), not to the nodes within the matrix.



          documentclass[tikz]standalone
          usetikzlibrarymatrix,fit
          begindocument
          begintikzpicture
          matrix (m) [%
          matrix of nodes,%
          nodes in empty cells,%
          nodes=rectangle, draw ,align=center,minimum height=1.5cm, text
          width=3.5cm,font=scriptsize, inner sep= 0cm, outer sep= 0cm,
          fill=white,anchor=center,%
          column sep=.5cm,%
          row sep=.5cm,%
          anchor=center
          ]%

          & Two\ line \breaks & One line && \
          One\linebreak&&&& \
          &&&Two\line\breaks& \
          &&One&& \
          ;
          foreach row/rownext in 1/2,2/3,3/4,4/4

          foreach col/colnext in 1/2,2/3,3/4,4/5,5/5

          draw(m-row-col) to (m-row-colnext);
          draw(m-row-col) to (m-rownext-col);


          endtikzpicture
          enddocument


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          marmot

          58.5k463126




          58.5k463126











          • I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
            – marmot
            3 hours ago










          • The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
            – Ignasi
            6 mins ago
















          • I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
            – marmot
            3 hours ago










          • The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
            – Ignasi
            6 mins ago















          I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
          – marmot
          3 hours ago




          I think this has been first pointed out in tex.stackexchange.com/a/18761/121799.
          – marmot
          3 hours ago












          The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
          – Ignasi
          6 mins ago




          The problem here is different from the one you pointed. The use of matrix of nodes changes node's anchor to base which means than empty cells and nodes with text will align on their base anchor, not through the center. Loop Space explained to me also long time ago ;-).
          – Ignasi
          6 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f451528%2ftikz-matrix-nodes-are-not-in-a-row%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery