# Aligning underset below matrix equation

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:

My code is:

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

\begin{document}

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

• Welcome to TeX.SX! Please help us (and also you) and add a full minimal working example (MWE), with preamble. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Nov 11 '17 at 17:29

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}

$$\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{document}


- don't leave blank lines inside of any math; this will always result in an error.
- i removed an extra from the provided example.

• It should be \mathbb{R}^{m\times n}; also \pmb leads to bad output and \bm should be used instead. – egreg Nov 11 '17 at 19:01
• @egreg -- to paraphrase @egreg, "i just used what was provided by the op." (but i agree that using \bm is much to be preferred. i fixed the superscript. – barbara beeton Nov 11 '17 at 19:21
• Thanks a lot for the solution and the comments. I was giving an integer to \vphantom, I’m new.. – kneazle Nov 12 '17 at 10:31
• @kneazle -- you can let us know which answer you found most useful by clicking on the check mark that appears by the answer. – barbara beeton Nov 12 '17 at 15:20

You can use an array:

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

\begin{document}
$$\begin{array}{@{}c@{}c@{}c@{}c@{}} \begin{bmatrix} 18\\5\\15\\-9\\-3\\ \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} & \begin{bmatrix} 2\\ 3\\ -2\\ -5\\ 1\\ 4 \end{bmatrix} \\[1ex] \mathclap{\scriptstyle\bm{y}\in \mathbb{R}^m} && \mathclap{\scriptstyle\bm{A}\in \mathbb{R}^{m\times n}} & \mathclap{\scriptstyle\bm{x}\in \mathbb{R}^n} \end{array}$$
\end{document}


Note that it should be \mathbb{R}^{m\times n} and that you should use \bm rather than \pmb.