[Tex/LaTex] Redefining \bordermatrix

arraysbordermatrixmatrices

Greetings to all of the community!
Could anyone help on redefining the \bordermatrix to get results as shown?

https://tex.stackexchange.com/questions/59517/label-rows-of-a-matrix-by-characters

The initial question was about changing form of braces (and there is a thread about it) was quite easy to deal with, since Knuth gave said definition in TexBook (though it has some minor differences with the one given on the forum here). But how should i change those lines to get it done?

The \kbordermatrix and \blockarray (the image is taken from thread about those two) are out of the question, because our editorial is harsh on new usepackages at the moment. Or forever maybe)

First time here, looked through suggested questions, but simply might not see the answer. If any rules of form were violated by my first attempt, please give a good kick)

Best Answer

Define your own bordermatrix, derived from the one in latex.ltx:

\documentclass{article}
\makeatletter
\def\BorderMatrix#1{%
    \begingroup
    \m@th\@tempdima8.75\p@\setbox\z@\vbox{%
        \def\cr{\crcr\noalign{\kern2\p@\global\let\cr\endline }}%
        \ialign{\hfil$##$\hfil\kern2\p@\kern\@tempdima & \thinspace 
            \hfil $##$\hfil && \quad\hfil $##$\hfil\crcr\omit\strut
            \hfil\crcr\noalign{\kern-\baselineskip}#1\crcr\omit
            \strut\cr}}%
    \setbox\tw@\vbox{\unvcopy\z@\global\setbox\@ne\lastbox}%
    \setbox\tw@\hbox{\unhbox\@ne\unskip\global\setbox\@ne\lastbox}%
    \setbox\tw@\hbox{%
        $\kern\wd\@ne\kern-\@tempdima\left(\kern2pt
        \global\setbox\@ne\vbox{\box\@ne\kern2\p@}%
        \vcenter{\kern -\ht\@ne \unvbox\z@\kern-\baselineskip}%
        \kern-2\@tempdima\kern4\p@\right)$}%
    \null\;\vbox{\kern\ht\@ne\box\tw@}%
    \endgroup
}
\makeatother
\begin{document}

    $\bordermatrix{%
           &  1 &  2 \cr
         1 & x1 & x2 \cr
         2 & x3 & x4 \cr
         3 & x5 & x6 \cr
        }$
    \qquad
    $\BorderMatrix{%
         1 & 2  &    \cr
        x1 & x2 & 1 \cr
        x3 & x4 & 2 \cr
        x5 & x6 & 3 \cr
    }$

\end{document}

enter image description here

Related Question