Tikz 在矩阵中的定位

Tikz 在矩阵中的定位

由于 StackExchange 上一些帖子的帮助(主要是 [1] 和 [2]),我认为我掌握了在 TikZ 中用括号对矩阵行和列进行分类并用线条分隔它们的要点。但是,我无法使 draw 命令中的位置引用起作用,奇怪的是,只能在某些矩阵内起作用。链接中的示例(4x4 矩阵)编译完美,但下面更大的矩阵却不能。(我只将示例中较小的矩阵与较大的矩阵进行了交换。)

\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}

具体来说,我收到错误消息“!Package pgf 错误:没有已知名为 m-4-2 的形状。”,该消息出现在绘制虚线的第一行。但是,名为 m-1-3 和 m-1-2 的形状是已知的。我在这里不知所措,因为我无法将错误与可能出错的代码联系起来。

[1]如何用括号指定矩阵的两级行和列标签?

[2]在 TikZ 分区线中创建数学矩阵

答案1

将选项添加nodes in empty cells到矩阵,以便能够引用这些节点:

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

相关内容