# How to improve the display of this E_ij (canonical matrix)?

Here is my attempt:

$E_{ij} = \begin{blockarray}{ccccccc} & & \text{j-th column} & & \\ & & \downarrow & & \\ \begin{block}{(ccccc)cc} & & \vdots& \\ & & 0& \\ \cdots &0 & 1& 0 & \cdots &\leftarrow&\text{i-th row}\\ & & 0& \\ & & \vdots& \\ \end{block} \end{blockarray}$


I see two problems:

1. the text "j-th column" makes the column too wide.

2. The $E_ij$ is not centered relative to the parenthesis.

How can I solve these problems?

The hard way. ;-)

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\NewDocumentCommand{\canonicalmatrix}{mO{th}mO{th}}{%
\begin{array}{@{}c@{}}
\vphantom{
\begin{array}{@{}c@{}}\text{$#3$-#4 column}\\\downarrow\end{array}
}
\\
\hphantom{E_{#1#3}={}\enspace}
\begin{pmatrix}
& & \smash[t]{
\begin{array}[b]{@{}c@{}}
\makebox[0pt]{$#3$-#4 column}\\
\downarrow\$-.5ex] \vdots \end{array} } \\ & & 0 \\ \llap{E_{#1#3}={}\quad} \cdots & 0 & 1 & 0 & \cdots\rlap{\quad\leftarrow #1-#2 row} \\ & & 0 \\ & & \vdots \end{pmatrix} \end{array}%\hphantom{\text{\enspace\leftarrow #1-#2 row}} } \begin{document} \[ \canonicalmatrix{i}{j}$
$\canonicalmatrix{2}[nd]{3}[rd]$

\end{document}


Here it is using a TABstack.

\documentclass{article}
\usepackage{tabstackengine,amsmath}
\stackMath
\def\Vdots{\smash{\protect\raisebox{-1.5pt}{$\vdots$}}}
\begin{document}
$\setstacktabbedgap{1.5ex} E_{ij} = \stackon{\parenMatrixstack{ & & \Vdots& &\\ & & 0& \\ \cdots & 0 & 1& 0 & \cdots\\ & & 0& \\ & & \Vdots& }}{\stackunder{\text{j-th column}}{\downarrow}}\leftarrow\text{i-th row}$
\end{document}