[Tex/LaTex] Aligning underset below matrix equation

amsmathequationsmatricessubscripts

I wonder how I can align undersets below equations of matrix.
I tried underset and stack under for the scripts, and tried vphantom for aligning. Your help will be much appreciated!

I need the below equation: enter image description here

But instead, I have this:enter image description here

My code is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{mathtools}

\begin{document}    
\begin{equation}

\begin{equation}
\underset{\pmb{y}\in \mathbb{R}^m}{\begin{bmatrix}
18\\5\\15\\-9\\-3\\
\end{bmatrix}}= 
\underset{\pmb{A}\in \mathbb{R}^m\times n}{\begin{bmatrix}
4 & 0 & 0 & -2 & 0 & 0 \\
0 & 0 & -1 & 0 & 3 & 0\\
0 & 5 & 0 & 0 & 0 & 0 \\
1 & 0 & 0 & -1 & 0 & -4 \\
1 & 0 & 0 & 0 & -5 & 0
\end{bmatrix}}
\underset{\pmb{x}\in \mathbb{R}^n}{\begin{bmatrix}
2\\ 3\\ -2\\ -5\\ 1\\ 4
\end{bmatrix}}

\end{equation}
\end{document}

Best Answer

very simple ... just add a \vphantom of the height of the tallest matrix to the other two.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{mathtools}

\begin{document}    

\begin{equation}
\underset{\pmb{y}\in \mathbb{R}^m}{%
\vphantom{\begin{bmatrix}0\\0\\0\\0\\0\\0\end{bmatrix}}
\begin{bmatrix}
18\\5\\15\\-9\\-3\\
\end{bmatrix}}= 
\underset{\pmb{A}\in \mathbb{R}^{m\times n}}{%
\vphantom{\begin{bmatrix}0\\0\\0\\0\\0\\0\end{bmatrix}}
\begin{bmatrix}
4 & 0 & 0 & -2 & 0 & 0 \\
0 & 0 & -1 & 0 & 3 & 0\\
0 & 5 & 0 & 0 & 0 & 0 \\
1 & 0 & 0 & -1 & 0 & -4 \\
1 & 0 & 0 & 0 & -5 & 0
\end{bmatrix}}
\underset{\pmb{x}\in \mathbb{R}^n}{\begin{bmatrix}
2\\ 3\\ -2\\ -5\\ 1\\ 4
\end{bmatrix}}
\end{equation}
\end{document}

output of example code

a couple of comments:
- don't leave blank lines inside of any math; this will always result in an error.
- i removed an extra \begin{equation} from the provided example.

Related Question