[Tex/LaTex] Non-vertically-centered TikZ matrix of nodes cell content

plain-textikz-pgf

How can you make the matrix cell contents aligned to the top? I am using plain format with XeTeX.

\input tikz
\usetikzlibrary{matrix}
$$\hbox{I'd like for the cells to be top-aligned}\cases{
\tikzpicture[
  a/.style={draw=green!50!black,text width=3.5cm,
    text height=1.5cm,text depth=1.5cm,minimum size=3.5cm,
    anchor=base,
    inner sep=0pt,outer sep=0pt},
  m/.style={matrix of nodes,inner sep=2pt,outer sep=0pt,nodes=a,
    ampersand replacement=\&,row sep=0pt,column sep=0pt,draw=black!50}
  ]
  \parindent0pt
  \matrix[m] (mx) {
    Hey, this is a node with a break\break and stuff\&
    And another one with it. Milkshakes are yummy when the sun is shining\\
    Let's see what happens; I'm trying to find the logic\&
    Does it break when all these cells have different amount of text?\\
  };
  \draw[very thick,red!50] (mx.north)--(mx.south) (mx.west)--(mx.east);
\endtikzpicture
} \hbox{Yes it does}
$$
\bye

enter image description here

After @Gonzalo's comment to change text height/depth:

\input tikz
\usetikzlibrary{matrix}
\tikzpicture[
  a/.style={draw=green!50!black,text width=3.5cm,
    text height=0pt,text depth=2.5cm,minimum size=3.5cm,
    anchor=base,
    inner sep=0pt,outer sep=0pt},
  m/.style={matrix of nodes,inner sep=2pt,outer sep=0pt,nodes=a,
    ampersand replacement=\&,row sep=0pt,column sep=0pt,draw=black!50}
  ]
  \parindent0pt
  \matrix[m] (mx) {
    Hey, this is a node with a break\break and stuff\&
    And another one with it. Milkshakes are yummy when the sun is shining\\
    Let's see what happens; I'm trying to find the logic\&
    Does it break when all these cells have different amount of text?\\
  };
  \draw[very thick,red!50] (mx.north)--(mx.south) (mx.west)--(mx.east);
\endtikzpicture
\bye

enter image description here

Best Answer

A solution with matrix (version 2)

\input tikz
\usetikzlibrary{arrows,calc,matrix,decorations.pathreplacing} 
\parindent=0pt
\tikzpicture[
  b/.style={
      text width=3.2cm,,minimum height=0pt,,minimum width=0pt
      inner sep =.2cm,anchor=north west,
      align=left},
  m/.style={matrix of nodes,
            inner sep=2pt,
            outer sep=0pt,
            column sep=0pt,
            draw=black!50},
            nodes={minimum height=2cm,
                   minimum width=3.6cm}]
  \matrix[m] (M) {%
  {} & {} \\
   {}&  {}\\
  }; 

\node[b] at (M-1-1.north west){%
   Hey, this is a node with a break\break and stuff };
\node[b] at (M-1-2.north west){%
   And another one with it. Milkshakes are yummy when the sun is shining};
\node[b] at (M-2-1.north west){%
   Let's see what happens; I'm trying to find the logic };
\node[b] at (M-2-2.north west){%
   Does it break when all these cells have different amount of text?};      

\draw[very thick,red!50] (M-1-1.north east)--(M-2-1.south east)
                         (M-1-1.south west)--(M-2-2.north east);
\draw[double,green!50!black] (M-1-1.north west) rectangle (M-2-2.south east);
\draw[decorate,decoration={brace,mirror,raise=6pt}]%
     (M-1-1.north west)--(M-2-1.south west);
\node[anchor=east,left=1em] at (M-1-1.south west){%
      I'd like for the cells to be top-aligned};
\node[anchor=west] at (M-1-2.south east) {Yes it does}; 
\endtikzpicture    
\bye

enter image description here

Related Question