How can I label the columns and rows of a matrix?

I would like to label the columns and rows of a matrix (e.g. I, J, K, L and M) and ideally also provide an overall label for the rows (winner) and the columns (loser).

The corresponding functionality (at least for the column and row labels) seems to be in LaTeX through a variety of packages, e.g. matrices - Matrix with rows and columns labeled - TeX - LaTeX Stack Exchange

You may use table to recreate the matrix structure.

$ 
#table(
    columns: (auto,)+(3pt,)+(auto,)*5+(3pt,),
    stroke: none,
    align: (right + horizon,) + (center + horizon,)*7,
    [],[], $I$, $J$, $K$, $L$, $M$, [],
    $I$, table.cell(rowspan: 5, box(stroke: none, inset: (top: -0.5em), $lr("[", size: #875%)$)), $0$, $1$, $0$, $1$, $0$, table.cell(rowspan: 5, box(stroke: none, inset: (top: -0.5em), $lr("]", size: #875%)$)),
    $J$, $0$, $0$, $1$, $0$, $1$,
    [winner  $K$], $1$, $0$, $0$, $1$, $1$,
    $L$, $0$, $1$, $0$, $0$, $0$,
    $M$, $0$, $0$, $0$, $1$, $0$,
  )
 $

I don’t know a method that can automatically adjust the size of delimiters.

1 Like

Thanks for this solution; it does add the ‘winner’ but not the ‘loser’ (but presumably I could do that above the ‘K’ somehow).

It hadn’t occurred to me that I would be able to get the delimiters using a table but your solution is interesting and I could possibly adapt it so the size is calculated programmatically.