Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
What is the message you want to pass to? The dimension compability or the vector structure? –  percusse Jan 21 at 16:17

3 Answers 3

up vote 6 down vote accepted

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}

outputA

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}

outputB

\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}

outputC

share|improve this answer
    
Hi, one more question, How can I highlight the entire line of matrices using your code ? –  asd Jan 21 at 16:41
1  
@asd See updated answer. –  Svend Tveskæg Jan 21 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}

enter image description here

share|improve this answer

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}

enter image description here

share|improve this answer
    
This is probably the best solution if no coloring is needed. –  Svend Tveskæg Jan 21 at 18:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.