2

I try to plot this matrix (image) with this code but the shape of my equation has problem(second image) How I could correct it? enter image description here


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

enter image description here.

Roya
  • 59
  • 2
    Welcome to TeX:SE. YOu only need to add baseline to tikzpicture options: \begin{tikzpicture}[baseline, ...] – Zarko Jan 04 '21 at 17:32

2 Answers2

3

Let me extend my comment to answer:

  • you need to move matrix baseline to their vertical center
  • for this is sufficient to add option baseline to 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}

enter image description here

Addendum:

You may liked version written with help of the nicematrix package:

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

For final result you need to compile this MWE at least twice.

enter image description here

Zarko
  • 296,517
  • You're great; in the last version of 1-1-2021 there are also the arrows line out the matrix: Have you seen? +1. – Sebastiano Jan 04 '21 at 20:10
  • 1
    @Sebastiano, I just upgrade my installation with it, but so far haven't time to test it. Since year is young i will do this in near features ... – Zarko Jan 04 '21 at 20:12
  • Related question: https://tex.stackexchange.com/questions/396273/arrows-describing-matrix/577348#577348 – Sebastiano Jan 04 '21 at 20:17
  • 1
    @Sebastiano, before IO edit his question, I closed it as duplicate to question in your link. – Zarko Jan 04 '21 at 20:20
  • I have understood and all the best always. Hi. – Sebastiano Jan 04 '21 at 20:22
  • Thank you very much. It is great now. Of course I found another way for this, completely different, that I put it here. – Roya Jan 05 '21 at 14:13
  • @Roya, see solution in addendum to my answer. – Zarko Jan 05 '21 at 15:44
  • It is great! But how could I remove this warninig? destination with the same identifier (name{iRow.3}) has been already used, duplicate ignored \relax l.2140 \Block{2-2}\bigzero pdfTeX warning (ext4): destination with the same id – Roya Jan 05 '21 at 16:22
  • @Roya, which warning? – Zarko Jan 05 '21 at 16:23
  • this ---> destination with the same identifier (name{iRow.3}) has been already used, duplicate ignored \relax l.2140 \Block{2-2}\bigzero pdfTeX warning (ext4): destination with the same id – Roya Jan 05 '21 at 16:34
  • @Roya, with my MWE and recent LaTeX installation you should not receive any warnings. – Zarko Jan 05 '21 at 16:56
  • OK, It had problem with equation environment! Thank you very much for your time. – Roya Jan 05 '21 at 17:24
0
\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}

rt

Zarko
  • 296,517
Roya
  • 59