# How to reproduce a matrix with vectors labels?

I would like to write a matrix like the picture below (that is my target): But I'm struggling with f1 f2...f(e1) f(e2).

$\begin{pmatrix} a_{1,1} & & a_{1,j} & \dots & a_{1,p} \\ a_{2,1} & & a_{2,j} & \dots & a_{2,p} \\ \vdots & & \vdots & \ddots& \vdots \\ a_{n,1} & \dots & a_{n,j} & \dots & a_{n,p}\\ \end{pmatrix}$


• You can use kbordermatrix or blkarray. Commented Aug 22, 2017 at 22:00
• Commented Aug 22, 2017 at 23:01
• Related Question: Where is the \matrix command? Commented Aug 23, 2017 at 7:44

You can use \bordermatrix.

\documentclass{article}

\begin{document}
$\bordermatrix{ & f(e_1) & \dots & f(e_j) & \dots & f(e_p) \cr f_1 & a_{1,1} & & a_{1,j} & \dots & a_{1,p} \cr f_2 & a_{2,1} & & a_{2,j} & \dots & a_{2,p} \cr \vdots & \vdots & & \vdots & \ddots & \vdots \cr f_n & a_{n,1} & \dots & a_{n,j} & \dots & a_{n,p} \cr }$
\end{document}


A solution based on gauss:

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{mathtools}
\usepackage{gauss, array, pgffor}

\def\matlab{\mult}
\newenvironment{annotmatrix}[1][]{%
\let\rowmultlabel\text \let\colmultlabel\text\setlength{\rowarrowsep}{0pt}\setlength{\colarrowsep}{0.8ex}%
\gmatrix[#1]}
{\endgmatrix}

\begin{document}

$\renewcommand\arraystretch{1.3} \begin{tabular}{ >{\footnotesize\color{PaleGreen3}}c<{\!}@{}} f_1 \\[-0.8ex] f_2 \\ \vdots\\[-0.1ex] f_n \end{tabular} \begin{annotmatrix}[p]% a_{11} & \dots & a_{1j} & \dots &a_{1p} \\% a_{21} & \dots & a_{2j} & \dots &a_{2p} \\% \vdots & & \vdots & &\vdots \\% a_{n1} & \dots & a_{nj} & \dots &a_{np} \colops \foreach \i/\label in {0/ f({\color{RoyalBlue3}e_1}), 1/\dotsm, 2/ f({\color{RoyalBlue3}e_j}), 3/\dotsm, 4/ f({\color{RoyalBlue3}e_p})}{\matlab{\i}{\footnotesize \label}} \end{annotmatrix}$

\end{document}