I am trying to produce an nxn bmatrix that has both column and row headings. By following this manual with amsmath package and the code below:

a_{11}&a_{12}&\cdots &a_{1n} \\
a_{21}&a_{22}&\cdots &a_{2n} \\
\vdots & \vdots & \ddots & \vdots\\
a_{n1}&a_{n2}&\cdots &a_{nn}
\caption{Correlation Matrix}\label{fig:vulnmatrix}

I can produce this:

enter image description here

However, I aim at producing a bmatrix with column and row headings like this:

enter image description here

So far I have researched and all the examples I have encountered do not have headings. Can anyone suggest a solution for me?

  • 1
    the package blkarray is your friend. similar question was asked many times here. – Zarko Mar 28 '18 at 13:05
  • @Zarko can I have the labels to the left ? most examples have them on the right like those one provided in this answer (tex.stackexchange.com/questions/59517/…). My matrix isn't an equation. I did like this (tex.stackexchange.com/a/346979/61339), but in with labels on the left. – SyCode Mar 28 '18 at 13:23
  • yes, you can. Werners answer in the first link in you comment show, how to do this. – Zarko Mar 28 '18 at 14:09

A solution with blkarray, and another with gauss:

\usepackage{blkarray, bigstrut}



 & C_1 & C_2 & \dots & C_n \\
N_1 & a_{11}&a_{12}&\cdots &a_{1n}\bigstrut[t] \\
N_2 & a_{21}&a_{22}&\cdots &a_{2n} \\
 & \vdots & \vdots & \ddots & \vdots\\
N_n & a_{n1}&a_{n2}&\cdots &a_{nn}\bigstrut[b]\\
\caption{Correlation Matrix}\label{fig:vulnmatrix}

\begin{figure}[! htb]
    \mathllap{N_1\quad}a_{11}&a_{12}&\cdots &a_{1n} \\
     \mathllap{N_2\quad}a_{21}&a_{22}&\cdots &a_{2n} \\
    \vdots & \vdots & \ddots & \vdots\\
     \mathllap{N_n\quad}a_{n1}&a_{n2}&\cdots &a_{nn}\colops
\caption{Correlation Matrix}\label{fig:vulnmatrix}


enter image description here

| improve this answer | |
  • this works but not exactly since I am using an cloud latex engine (overleaf) which does not support kbordermatrix as stated here (tex.stackexchange.com/questions/249484/…). Thanks :) – SyCode Mar 28 '18 at 14:44
  • 1
    @SyCode: But I don't use kbordermatrix! – Bernard Mar 28 '18 at 14:54
  • you are absolutely correct @Bernard , sorry for the erroneous comment. I don't know how I got kbordermatrix into my code. Your answer solves my issue well !!! Many thanks. – SyCode Mar 28 '18 at 15:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.