Align matrices problem

I have an equation of matrices and I want to align the dimensions of the matrices below the equation of matrices. However, I produce something very ugly. Can someone advise how to make it look better or properly aligned ?

\documentclass[10pt,a4paper]{article}
\usepackage{amsmath, amsfonts}
\begin{document}
\begin{align*}
A
&
\begin{bmatrix}
&&\\
\vec{v}_1 & \cdots & \vec{v}_r \\
&&
\end{bmatrix}
&= &
\begin{bmatrix}
&&\\
\vec{u}_1 & \cdots & \vec{u}_r\\
&&
\end{bmatrix}
&
\begin{bmatrix}
\sigma_1 &&\\
&\ddots&\\
&& \sigma_r
\end{bmatrix}
\\
(m \times n) & (n \times r) & & (m \times r) & (r \times r)
\end{align*}
\end{document}

-
What is the message you want to pass to? The dimension compability or the vector structure? – percusse Jan 21 '14 at 16:17

A possible solution using tabular:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\setlength{\tabcolsep}{0pt}
\begin{tabular}{*{5}{c}}
$A$
& $\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& $=$
& $\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& $\begin{bmatrix} \sigma_1 & & \\ & \ddots & \\ & & \sigma_r \end{bmatrix}$\\
& $(m \times n)(n \times r)$
&
& $(m \times r)$
& $(r \times r)$
\end{tabular}

\end{document}


Update

If you want to color an entire row or individual cells, you can do the following (see also Highlighting in tabular environment):

\documentclass{article}

\usepackage{amsmath}
\usepackage{color,colortbl}

\definecolor{ColorA}{rgb}{0.25,0.5,0.75}

\begin{document}

\setlength{\tabcolsep}{0pt}
\begin{tabular}{*{5}{c}}
\cellcolor{ColorA}\,$A$
& \cellcolor{ColorA}$\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& \cellcolor{ColorA}$=$
& \cellcolor{ColorA}$\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& \cellcolor{ColorA}$\begin{bmatrix} \sigma_1 & & \\ & \ddots & \\ & & \sigma_r \end{bmatrix}$\\
& $(m \times n)(n \times r)$
&
& $(m \times r)$
& $(r \times r)$
\end{tabular}

\end{document}


\documentclass{article}

\usepackage{amsmath}
\usepackage{color,colortbl}

\definecolor{ColorA}{rgb}{0,1,1}
\definecolor{ColorB}{rgb}{1,0,1}
\definecolor{ColorC}{rgb}{1,1,0}
\definecolor{ColorD}{rgb}{0.25,0.5,0.75}

\begin{document}

\setlength{\tabcolsep}{0pt}
\begin{tabular}{*{5}{c}}
\cellcolor{ColorA}\,$A$\,
& \cellcolor{ColorB}$\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& \,$=$\,
& \cellcolor{ColorC}$\begin{bmatrix} & & \\ \vec{v}_1 & \cdots & \vec{v}_r \\ & & \end{bmatrix}$
& \cellcolor{ColorD}$\begin{bmatrix} \sigma_1 & & \\ & \ddots & \\ & & \sigma_r \end{bmatrix}$\\
& $(m \times n)(n \times r)$
&
& \,$(m \times r)$
& $(r \times r)$
\end{tabular}

\end{document}


-
Hi, one more question, How can I highlight the entire line of matrices using your code ? – mynameisJEFF Jan 21 '14 at 16:41
@asd See updated answer. – Svend Tveskæg Jan 21 '14 at 16:58

You can use subscripts, but in this particular case, this approach doesn't look completely fine. A better option could be to take a more "wordy" approach. The following example shows both possibilities:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$A_{m\times n} \begin{bmatrix} && \\ \vec{v}_1 & \cdots & \vec{v}_r \\ && \end{bmatrix}_{n\times r} = \begin{bmatrix} && \\ \vec{u}_1 & \cdots & \vec{u}_r\\ && \end{bmatrix}_{m\times r} \begin{bmatrix} \sigma_1 &&\\ &\ddots&\\ && \sigma_r \end{bmatrix}_{r\times r}$

So we have
$AV=U\Sigma,$
where $A$ is an $m\times n$ matrix and $V$, $U$ and $\Sigma$ are the $n\times r$, $m\times r$ and $r\times r$, respectively, matrices given by
$V= \begin{bmatrix} && \\ \vec{v}_1 & \cdots & \vec{v}_r \\ && \end{bmatrix},\quad U= \begin{bmatrix} && \\ \vec{u}_1 & \cdots & \vec{u}_r\\ && \end{bmatrix}\quad\text{and}\quad \Sigma= \begin{bmatrix} \sigma_1 &&\\ &\ddots&\\ && \sigma_r \end{bmatrix}.$

\end{document}


-

An attempt with \underset:

\documentclass[10pt,a4paper]{article}
\usepackage{amsmath, amsfonts}
\begin{document}
\begin{align*}
A \underset{\textstyle (m \times n) \, (n \times r)}{\begin{bmatrix}
&&\\
\vec{v}_1 & \cdots & \vec{v}_r \\
&&
\end{bmatrix}}
&=
\underset{\textstyle (m \times r)}{\begin{bmatrix}
&&\\
\vec{u}_1 & \cdots & \vec{u}_r\\
&&
\end{bmatrix}}
\underset{\textstyle (r \times r)}{\begin{bmatrix}
\sigma_1 &&\\
&\ddots&\\
&& \sigma_r
\end{bmatrix}}
\end{align*}
\end{document}


-
This is probably the best solution if no coloring is needed. – Svend Tveskæg Jan 21 '14 at 18:08