TikZ 等效于 bordermatrix,具有自动对齐标签的功能

TikZ 等效于 bordermatrix,具有自动对齐标签的功能

我想创建一个 TikZ 矩阵(单元格中包含图片),并以与 \bordermatrix 允许的方式注释此矩阵的行/列。这是我所追求的(大致)图片:

带图像的边框矩阵

这是生成它的 MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
  \matrix (M) [
    matrix of nodes,
    nodes in empty cells,
    inner sep=0pt,
    left delimiter={(},
    right delimiter={)}
  ]{
    \node[draw=none,fill=none] {
      \begin{tikzpicture}
        \path[use as bounding box] (0, 0) rectangle (1, 1);
        \fill (0.5, 0.5) circle[radius=0.5];
      \end{tikzpicture}
    }; & \\
    & \node[draw=none, fill=none] {
      \begin{tikzpicture}
        \path[use as bounding box] (0, 0) rectangle (2, 2);
        \fill (1.0, 1.0) circle[radius=1.0];
      \end{tikzpicture}
    }; \\
  };
  \node[left=12pt of M-1-1.west] {\(A\)};
  \node[above left=21pt and 27pt of M-2-1.west] {\(B\)};
\end{tikzpicture}
\end{document}

我怎样才能摆脱标签节点的硬编码相对定位,并使它们自动(1)放置在左分隔符的正外侧,以及(2)位于行的中心?

更新

这是通过调整的解决方案敲击中的示例如何将 Tikz 绘图的尺寸添加到方程的尺寸中“:

% corner node (unindented slightly to get away from parenthesis)
\node[anchor=south east, left=6pt] (M-0-0) at (M-1-1.north west) {};

% iterate over each row and their corresponding labels
\foreach[count=\i] \v in {\(A\),\(B\)}{

  % label of this row, based on size of diagonal element
  \node (M-\i-0) at (M-0-0 |- M-\i-\i) {};

  % put the text (specified in the loop) at the label
  \path (M-\i-0.north) -- (M-\i-0.south) node [midway, left] { \v };
}

答案1

可以通过使用 OP 的代码和链接的答案来实现结果,例如使用:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[baseline = (M.center),% center with respect to the matrix center
        every left delimiter/.style={xshift=1ex},%tighter delimiter spacing
        every right delimiter/.style={xshift=-1ex}]
\matrix (M) [matrix of nodes,left delimiter={(},right delimiter={)},nodes in empty cells 
        ]{ 
                              |[draw,circle,inner sep=3mm,fill]| &  \\
                                & |[draw,circle,inner sep=6mm,fill]|\\
};
\node[anchor=south east, left=6pt] (M-0-0) at (M-1-1.north west) {};
% iterate over each row and their corresponding labels
\foreach[count=\i] \v in {\(A\),\(B\)}{
  % label of this row, based on size of diagonal element
  \node (M-\i-0) at (M-0-0 |- M-\i-\i) {};
  % put the text (specified in the loop) at the label
  \path (M-\i-0.north) -- (M-\i-0.south) node [midway, left] { \v };
}
\end{tikzpicture}
\end{document}

给出

在此处输入图片描述

相关内容