14

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

Can anybody help?

Werner
  • 603,163
may you
  • 255

2 Answers2

10

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.

Moriambar
  • 11,466
Werner
  • 603,163
  • Hi Werner. I found your answer helpful. How does one selectively adjust the spacing between the block and the elements exterior to the block? – user001 Mar 21 '12 at 01:12
  • @user001: Just on one side, or both (right and above)? – Werner Mar 25 '12 at 21:29
  • Preferably I would like to adjust the spacing between the top elements and the matrix and the right elements and the matrix to different extents. – user001 Mar 26 '12 at 01:20
3

The package nicematrix has tools to address that kind of problem.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[
  \NiceMatrixOptions{code-for-first-row=\scriptstyle,code-for-last-row=\scriptstyle}
  A=\begin{pNiceMatrix}[first-row,last-col=3]
      1 & 2 & \\
      a & b & 3 \\
      c & d & 4 \\
      e & f &   \\
  \end{pNiceMatrix}
\]
\end{document}

Output of the above code

F. Pantigny
  • 40,250