# How to create a Matrix with Label on its top? [duplicate]

I've been trying to create a matrix (displayed in the image below), and I haven't been able to figure out so far. I've tried the following code (as an example), but its not quite the same as you can see in the image. Can someone please guide me about this?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blkarray}

\begin{document}

$\begin{blockarray}{ccccc} a & b & c & d & e \\ \begin{block}{(ccccc)} 1 & 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 & 1 \\ \end{block} \end{blockarray}$

\end{document}


## 3 Answers

With {bNiceMatrix} of nicematrix:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
$T_i = \begin{bNiceMatrix}[first-row] W_1 & W_2 & W_3 & \cdots & W_m \\ e_{11} & e_{22} & e_{31} & \cdots & e_{m1} \\ e_{12} & e_{22} & e_{32} & \cdots & e_{m2} \\ e_{13} & e_{23} & e_{33} & \cdots & e_{m3} \\ \vdots & \cdots & \cdots & \cdots & \vdots \\ e_{1K} & e_{2K} & e_{3K} & \cdots & e_{mK} \\ \end{bNiceMatrix}$
\end{document} • Thank you so much !!! – Anees Feb 4 at 6:54

There is \bordermatrix macro in plain TeX:

$$\delcode(=\delcode[ \delcode)=\delcode] T_i = \bordermatrix{ & W_1 & W_2 & W_3 & \cdots & W_m \cr & e_{11} & e_{21} & e_{31} & \cdots & e_{m1} \cr & e_{12} & e_{22} & e_{32} & \cdots & e_{m2} \cr & e_{13} & e_{23} & e_{33} & \cdots & e_{m3} \cr & \vdots & \cdots & \cdots & \cdots & \vdots \cr & e_{13} & e_{23} & e_{33} & \cdots & e_{m3} \cr }$$

\bye


You are almost done, you only need to change tip of brackets in block and replace matrix elements, where you like to have dots with \cdots for horizontal dots and \vdots for vertical:

\documentclass{article}
\usepackage{blkarray}

\begin{document}
$T_i = \begin{blockarray}{ccccc} W_1 & W_2 & W_3 & \cdots & W_m \\ \begin{block}{[ccccc]} % <--- observe [ and ] e_{11} & e_{22} & e_{31} & \cdots & e_{m1} \\ e_{12} & e_{22} & e_{32} & \cdots & e_{m2} \\ e_{13} & e_{23} & e_{33} & \cdots & e_{m3} \\ \vdots & \cdots & \cdots & \cdots & \vdots \\ % <--- observe dots e_{1K} & e_{2K} & e_{3K} & \cdots & e_{mK} \\ % <--- observe dots \end{block} \end{blockarray}$
\end{document}


Code is simple and for final result need only one compilations. 