绘制矩阵,用箭头描述

绘制矩阵,用箭头描述

我尝试使用此代码绘制此矩阵(图像),但是我的方程的形状有问题(第二张图像)我该如何纠正它? 在此处输入图片描述


    \documentclass[12pt]{article}
    \usepackage{amsmath}
    \usepackage{nicematrix}
    \usepackage{amscd}
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta, matrix, quotes, positioning}
    \begin{document}
            \begin{equation}\label{key}
                \left[ \left. \left( t_{A}\vert E_{\lambda_{i}}(A)\right)\right| X^{i}, X^{i} \right] =
                \begin{tikzpicture}[LA/.style = {Straight Barb-Straight Barb,
                        shorten <=1pt, shorten >=1pt,
                        draw=blue}
                    ]
                    \matrix (m) [matrix of math nodes,
                    left  delimiter={[},
                    right delimiter={]}
                    ]
                    {
                        \lambda_{i}&&0&\\
                        &\lambda_{i} &&\\
                        0 && \ddots &\\
                        &&& \lambda_{i}\\
                    };
                    %\draw (m-1-3.north east) -- (m-5-3.south east);
                    %\draw (m-4-1.north west) -- (m-4-5.north east);
                    %
                    \draw[LA] (m-3-1.south west |- m.south) to [" $d_{i}$ " '] (m-4-4.south east |- m.south);
                    %\draw[LA] (m-5-4.south west |- m.south) to ["2" '] (m-5-5.south east |- m.south);
                    %
                    \coordinate[right=5mm of m.east] (e);
                    \draw[LA] (m-1-3.north east -| e) to [" $d_{i}$ "] (m-4-4.south east -| e);
                    %\draw[LA] (m-4-5.north east -| e) to ["2"] (m-5-5.south east -| e);
                \end{tikzpicture}
            \end{equation}
    \end{document}

在此处输入图片描述

答案1

让我扩展我的评论来回答:

  • 您需要将矩阵基线移动到其垂直中心
  • 这足以添加baseline选项tikzpicture
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amscd}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, matrix, quotes, positioning}
\begin{document}
        \begin{equation}\label{key}
            \left[\bigl( t_{A}\vert E_{\lambda_{i}}(A)\bigr)\middle| X^{i}, X^{i} \right] =
            \begin{tikzpicture}[baseline, %<------
            LA/.style = {Straight Barb-Straight Barb,
                         shorten <=1pt, shorten >=1pt,
                         draw=blue}
                                ]
                \matrix (m) [matrix of math nodes,
                            left  delimiter={[},
                            right delimiter={]}
                ]
                {
                    \lambda_{i}&&0&\\
                    &\lambda_{i} &&\\
                    0 && \ddots &\\
                    &&& \lambda_{i}\\
                };
                \draw[LA] (m-3-1.south west |- m.south) to [" $d_{i}$ " '] (m-4-4.south east |- m.south);
                \coordinate[right=5mm of m.east] (e);
                \draw[LA] (m-1-3.north east -| e) to [" $d_{i}$ "] (m-4-4.south east -| e);
            \end{tikzpicture}, \ i=1,\dotsc,k
        \end{equation}
\end{document}

在此处输入图片描述

附录:

您可能喜欢使用该nicematrix软件包编写的版本:

\documentclass[12pt]{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}
    \begin{equation}
\NiceMatrixOptions
{code-for-last-col=\color{blue},
 code-for-last-row=\color{blue}}
\left[
\bigl( t_{A}\vert E_{\lambda_{i}}(A)\bigr)\middle| X^{i}, X^{i} 
\right] = 
\begin{bNiceMatrix}[last-row,last-col]
\lambda_{i} &               & \Block{2-2}<\huge>{0} &   \\       
            & \lambda_{i}   &        &              & \quad\Vdots[line-style={solid,<->}]^{d_i}     \\
\Block{2-2}<\huge>{0} 
            &               & \ddots &              &   \\
            &               &        & \lambda_{i}  &   \\
& \Ldots[line-style={solid,<->}]_{d_i}              &   \\
\end{bNiceMatrix}\ ,\  i=1,\dotsc,k
    \end{equation}
\end{document}

为了获得最终结果,您需要至少编译两次此 MWE。

在此处输入图片描述

答案2

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{8.75}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}
\newcommand{\tikzmark}[1]{\tikz[overlay, remember picture] \coordinate (#1);}
\begin{document}
\[
    \left[ \left. \left( t_{A}\vert E_{\lambda_{i}}(A)\right)\right| X^{i}, X^{i} \right] =\quad \bbordermatrix{~  &\tikzmark{harrowleft}  &  &  & 
        \tikzmark{harrowright}\cr
        \tikzmark{varrowtop} & \lambda_{i }&  & 0 & \cr
        && \lambda_{i} &&  \cr
        & 0 && \ddots &\cr
        \tikzmark{varrowbottom} &  &  & &  \lambda_{i}  \cr
    }
    ,\quad i=1,\dots, k.
\]
\tikz[overlay,remember picture] {
    \draw[<->] ([yshift=2ex]harrowleft) -- ([yshift=2ex]harrowright)
    node[midway,above] {\scriptsize $ d_{i} $};
    \draw[<->] ([yshift=1.5ex,xshift=-2ex]varrowtop) -- ([xshift=-2ex]varrowbottom)
    node[near end,left] {\scriptsize $d_{i}$};
}
\end{document}

響

相关内容