[Tex/LaTex] Tikz positioning in matrices

matricespositioningtikz-pgf

Due to the help of some posts on StackExchange (mostly [1] and [2]) I think that I got the gist of categorizing matrix rows and columns with braces and separating them with lines in TikZ. However, I can't get the referencing of the positions in the draw command to work, strangely enough only within a certain matrices. The examples in the links (4×4 matrices) compile flawlessly, but the bigger matrix below doesn't. (I only exchanged the smaller matrices in the examples with the bigger matrix.)

\begin{tikzpicture}[decoration=brace,every left delimiter/.style={xshift=3pt},
                    every right delimiter/.style={xshift=-3pt},node distance=-1ex]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),
         row sep=0.5cm,column sep=0.5cm] (m) {
    x & x & \otimes & x       & x       & x       &         &         &         &         &         &         & \\
      &   &         & \otimes & x       &         & x       & x       &         & x       &         &         & \\          
    x &   & x       &         & \otimes &         &         &         &         &         &         &         & \\
      &   &         &         &         & \otimes & x       &         &         &         &         & x       & \\     
      &   &         &         &         &         & \otimes & x       &         &         &         & x       & \\
      &   &         &         &         &         & x       & \otimes &         & x       &         &         & \\
      &   &         &         &         &         &         &         & \otimes & x       &         &         & \\
      &   &         &         &         &         &         &         & x       & \otimes & x       &         & \\
      &   &         &         &         &         &         &         &         &         & \otimes & x       & \\
      &   &         &         &         &         &         &         &         &         &         & \otimes & \\    
      &   &         &         &         &         &         &         &         &         & x       &         & \\            
      &   &         &         &         &         &         &         &         &         & x       & x       & \\        
      &   &         &         &         &         &         &         &         &         &         & x       & \\};
\draw[dashed] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
  ($0.5*(m-4-2.south east)+0.5*(m-4-3.south west)$);
\draw[dashed] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
  ($0.5*(m-2-4.south east)+0.5*(m-3-4.north east)$);
\node[above=10pt of m-1-1] (top-1) {a};
\node[above=10pt of m-1-2] (top-2) {b};
\node[above=10pt of m-1-3] (top-3) {c};
\node[above=10pt of m-1-4] (top-4) {d};

\node[left=12pt of m-1-1] (left-1) {$\alpha$};
\node[left=12pt of m-2-1] (left-2) {$\beta$};
\node[left=12pt of m-3-1] (left-3) {$\gamma$};
\node[left=12pt of m-4-1] (left-4) {$\delta$};

\node[rectangle,above delimiter=\{] (del-top-1) at ($0.5*(top-1.south) +0.5*(top-2.south)$) {\tikz{\path (top-1.south west) rectangle (top-2.north east);}};
\node[above=10pt] at (del-top-1.north) {$A$};
\node[rectangle,above delimiter=\{] (del-top-2) at ($0.5*(top-3.south) +0.5*(top-4.south)$) {\tikz{\path (top-3.south west) rectangle (top-4.north east);}};
\node[above=10pt] at (del-top-2.north) {$B$};

\node[rectangle,left delimiter=\{] (del-left-1) at ($0.5*(left-1.east) +0.5*(left-2.east)$) {\tikz{\path (left-1.north east) rectangle (left-2.south west);}};
\node[left=10pt] at (del-left-1.west) {$C$};
\node[rectangle,left delimiter=\{] (del-left-2) at ($0.5*(left-3.east) +0.5*(left-4.east)$) {\tikz{\path (left-3.north east) rectangle (left-4.south west);}};
\node[left=10pt] at (del-left-2.west) {$D$};

\end{tikzpicture}

Specifically, I get the error message "!Package pgf Error: No shape named m-4-2 is known.", which occurs in the first line where the dashed line is drawn. However, the shapes named m-1-3 and m-1-2 are known. I am out of my wits here, as I can't make a connection between the errors and the code that could be wrong.

[1] How to Specify two level row and column labels of a matrix by braces?

[2] Create a math matrix in TikZ partition lines

Best Answer

Add the option nodes in empty cells to the matrix, to be able to refer to those nodes:

\matrix [matrix of math nodes, left delimiter=(,right delimiter=),
         row sep=0.5cm, column sep=0.5cm, nodes in empty cells] (m) { ...
Related Question