# Text above matrices

I am new to latex and I am trying to create

So far I have been able to create the matrices, like so:

$N\textrm{ spectra} \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1M} \\ a_{21} & a_{22} & \cdots & a_{2M} \\ \vdots & \vdots & \ddots & \vdots \\ a_{N1} & a_{N2} & \cdots & a_{NM} \end{bmatrix}\ \quad \begin{bmatrix} e_1 \\ e_2 \\ \vdots \\ e_N \end{bmatrix}$


Does anyone know how can I add text above the matrices?

-

Try this with stackrel and mbox's

$N\textrm{ spectra} \stackrel{\mbox{M components}}{% \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1M} \\ a_{21} & a_{22} & \cdots & a_{2M} \\ \vdots & \vdots & \ddots & \vdots \\ a_{N1} & a_{N2} & \cdots & a_{NM} \end{bmatrix}% }\ \quad \stackrel{\stackrel{\mbox{error}}{\mbox{detection}}}{% \begin{bmatrix} e_1 \\ e_2 \\ \vdots \\ e_N \end{bmatrix}% }$


-
Thank you! This is what I was looking for. –  aperez Jan 29 '12 at 13:56
You're welcome. There is probably a better way of doing this, but this was the first thing to come to mind. –  qubyte Jan 29 '12 at 14:00

The easiest way is to use array:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{array}{ccc} & & \text{error} \\ & \text{M components} & \text{detection} \\ \text{N spectra} & \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1M} \\ a_{21} & a_{22} & \cdots & a_{2M} \\ \vdots & \vdots & \ddots & \vdots \\ a_{N1} & a_{N2} & \cdots & a_{NM} \end{bmatrix} & \begin{bmatrix} e_1 \\ e_2 \\ \vdots \\ e_N \end{bmatrix} \end{array}$
\end{document}


-

text where above the matrix? If you want a kind of heading above each column, then probably \bordermatrix is your friend, a plain TeX command but usable in LaTeX.

If you want a single item over the whole matrix, then any latex stacking construct would do the job, stackrel or a second single column array environment with your bmatrix on the second row or....

update: sorry I see you want this second form, didn't notice the image link originally.

so....

$N\textrm{ spectra} \begin{smallmatrix} M\textrm{ components}\\\begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1M} \\ a_{21} & a_{22} & \cdots & a_{2M} \\ \vdots & \vdots & \ddots & \vdots \\ a_{N1} & a_{N2} & \cdots & a_{NM} \end{bmatrix}\end{smallmatrix}\ \quad \begin{smallmatrix} \textrm{error}\\ \textrm{detection}\\ \begin{bmatrix} e_1 \\ e_2 \\ \vdots \\ e_N \end{bmatrix}\end{smallmatrix}$

-

For future interest, if your labeling needs become more complicated, there is the qbordermatrix package which is somewhat more flexible than \bordermatrix as you can label rows or columns and put the labels on any of the four sides of the matrix. I have used this a bit, but have just noticed that the delimiters seem to extend somewhat higher above the top row of matrix elements than I would like.

Some of the questions on the TikZ package have also been helpful for my early attempts at more complicated labeling of matrices. For example, see the responses on using braces to label some number of rows or columns of a matrix .

There is also the kbordermatrix package which seems initially designed to label the along the top and down the left side of a matrix. The documentation says "I also have an experimental version that will put the labels on the right and bottom. If you ask, I will make it available." This package does seem to do a better job than qbordermatrix of making the top of the delimiters an appropriate height above the top row of matrix elements.

For a more flexible solution I think I'm going to have to play with tikz more now that I know how to use tikz in amsmath environments like align and gather .

-
Do you mind adding kbordermatrix to your answer for the sake of completeness? It can be found on this page. And the documentation is on this link –  percusse Jun 18 '12 at 14:13
@percusse You make a very good point. I had neglected this one some time ago as it didn't immediately seem designed to put labels below the bottom of a matrix, but the kbordermatrix package does have some advantage over the qbordermatrix for better delimiter sizing. –  Jason Whyte Jun 19 '12 at 7:23