使用 tikz 定义矩阵

使用 tikz 定义矩阵

嗨,我想把 Sigma 放在中心来定义一个矩阵。但我没能做到。有什么建议吗?

\begin{equation}
  \mathbf{\Sigma} = \begin{tikzpicture}[baseline=($\mathbf{\Sigma}$.center)]
  \begin{tikzpicture}
      \matrix[matrix of math nodes,left delimiter = {[},right delimiter ={]},row sep=10pt,column sep = 10pt] (m)
  {
    \Sigma_{1,1}&\Sigma_{1,2} &\Sigma_{1,1}\\
    \Sigma_{2,1}&\Sigma_{2,2} &\Sigma_{2,1}\\
    \Sigma_{1,1}&\Sigma_{1,2} &\Sigma_{1,1}\\
  };
  \begin{pgfonlayer}{background}
    \node[inner sep=3pt,fit=(m-1-1)]          (1)   {};
    \node[inner sep=3pt,fit=(m-2-1) (m-3-2)]  (2)   {};
    \node[inner sep=3pt,fit=(m-3-3)]          (3)   {};
    \draw[rounded corners,dotted,fill=green!50!white,inner sep=3pt,fill opacity=0.1]
    (1.north west) |- (3.south east) |- (2.east) |- (2.north) |- (1.north) -- cycle;
  \end{pgfonlayer}
\end{tikzpicture}
\end{equation}

答案1

正如我的评论所述,您可以尝试使用baseline={([yshift=-1ex]current bounding box.center)}(请参阅这个答案), 喜欢:

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds,calc,fit}

\begin{document}

\begin{equation}
  \mathbf{\Sigma} = \begin{tikzpicture}[baseline={([yshift=-1ex]current bounding box.center)}]
    \matrix[matrix of math nodes,left delimiter={[},right delimiter={]},row sep=10pt,column sep=10pt] (m) {
      \Sigma_{1,1} & \Sigma_{1,2} & \Sigma_{1,1} \\
      \Sigma_{2,1} & \Sigma_{2,2} & \Sigma_{2,1} \\
      \Sigma_{1,1} & \Sigma_{1,2} & \Sigma_{1,1} \\
    };
    \begin{pgfonlayer}{background}
      \node[inner sep=3pt,fit=(m-1-1)]          (1) {};
      \node[inner sep=3pt,fit=(m-2-1) (m-3-2)]  (2) {};
      \node[inner sep=3pt,fit=(m-3-3)]          (3) {};
      \draw[rounded corners,dotted,fill=green!50!white,inner sep=3pt,fill opacity=0.1]
        (1.north west) |- (3.south east) |- (2.east) |- (2.north) |- (1.north) -- cycle;
    \end{pgfonlayer}
  \end{tikzpicture}
\end{equation}

\end{document}

结果:

在此处输入图片描述

相关内容