[Tex/LaTex] Write elements above and right outside the matrix

bordermatrixmatrices

I found writing matrix's code is a boring work. There is one, you can see in pic below.

Can anybody help?

Best Answer

This is definitely possible when using the blkarray package. Here's a mock-up with some index styling (in \scriptsize):

enter image description here

\documentclass{article}
\usepackage{blkarray}% http://ctan.org/pkg/blkarray
\newcommand{\matindex}[1]{\mbox{\scriptsize#1}}% Matrix index
\begin{document}
\[
  A=\begin{blockarray}{ccc}
    \matindex{1} & \matindex{2} & \\
    \begin{block}{(cc)c}
      a & b & \matindex{3} \\
      c & d & \matindex{4} \\
      e & f &   \\
    \end{block}
  \end{blockarray}
\]
\end{document}

This would also be doable using a plain array, but would require additional vertical alignment/compensation, perhaps removing some of the code readability that exists via blkarray.