# Labelling Ax = b under an actual Matrix

I wish to achieve the following in Latex:

| a b | x | x1 | = | b1 |
| c d |   | x2 |   | b2 |
A         x       b


Where I write the labels A, x, and b under the respective matrices. The code I'm using to write the Matrices is (feel free to improve the my code -- I am suffering from over a decade of LateX abstinence).

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\times
\begin{pmatrix}
x1 \\
x2
\end{pmatrix}
=
\begin{pmatrix}
b1  \\
b2
\end{pmatrix}
\end{align}
\end{document}


Thanks.

-
–  Qrrbrbirlbel Oct 20 '12 at 22:41
I'd never use \times for matrix multiplication; no symbol is what's generally used. –  egreg Oct 20 '12 at 22:43
egreg ... what would you use ... didn't understand "no symbol" –  user1172468 Oct 20 '12 at 23:23
I understood egreg to say that he would not use any symbol at all: see his answer below for an example. (And I would agree that you should not use a symbol --- especially not \times, which when it is used in a short formula such as this would be typically confused for the cross product.) –  Niel de Beaudrap Oct 20 '12 at 23:47

Here's a perhaps better version, with a new environment which accepts the subscript as argument:

\documentclass{article}
\usepackage{amsmath}

\newenvironment{spmatrix}[1]
{\def\mysubscript{#1}\mathop\bgroup\begin{pmatrix}}
{\end{pmatrix}\egroup_{\textstyle\mathstrut\mysubscript}}

\begin{document}
$$\begin{spmatrix}{A} a & b \\ c & d \end{spmatrix} \begin{spmatrix}{x} x_1 \\ x_2 \end{spmatrix} = \begin{spmatrix}{b} b_1 \\ b_2 \end{spmatrix}$$
\end{document}


Note: too big subscripts may cause misalignment.

I wouldn't use \times for matrix multiplication: no symbol is generally used.

Also align for a single equation is wrong.

If someone is asking why the \def\mysubscript{#1} bit in the definition, the answer is that LaTeX doesn't allow using #1 in the "end" part of \newenvironment. This limitation does not hold with xparse:

\usepackage{xparse}
\NewDocumentEnvironment{spmatrix}{ m }
{\mathop\bgroup\begin{pmatrix}}
{\end{pmatrix}\egroup_{\textstyle\mathstrut #1}}

-
Why do you use \mysubscript and not #1 directly in the subscript? –  Tobi Oct 21 '12 at 9:30
@Tobi It's a limitation of \newenvironment: you can't use the parameters in the "end" part of the definition. This is not the case with \NewDocumentEnvironment from xparse. –  egreg Oct 21 '12 at 9:31
Oh sure … I didn’t see that it was an environment O:-) –  Tobi Oct 21 '12 at 10:07

It can be achieved by putting the matrix and the vectors inside \mathop. The example also uses \textstyle for a larger size and \vphantom for adjusting the baselines.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\mathop{\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}}_{\textstyle A}
\times
\mathop{\begin{pmatrix}
x1 \\
x2
\end{pmatrix}}_{\textstyle x\vphantom{A}}
=
\mathop{\begin{pmatrix}
b1  \\
b2
\end{pmatrix}}_{\textstyle b\vphantom{A}}
\end{align}
\end{document}


\documentclass{article}
\usepackage{amsmath}
\newcommand*{\putunder}[2]{%
{\mathop{#1}_{\textstyle #2}}%
}
\begin{document}
\begin{gather}
\putunder{
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
}{A}
\times
\putunder{
\begin{pmatrix}
x1 \\
x2
\end{pmatrix}
}{x\vphantom{A}}
=
\putunder{
\begin{pmatrix}
b1  \\
b2
\end{pmatrix}
}{b\vphantom{A}}
\end{gather}
\end{document}


-

Here is one that abuses a feature of mathtools (a supplement and some correction to amsmath features. Check the documentation) which I use often. It's actually drawing a bracket but zeroing it's linewidth makes it invisible. It's not elegant but still I didn't have any problems yet (doesn't mean I won't).

The command is \underbracket[<rule thickness>] [<bracket height>]{<arg>}

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$\underbracket[0pt][0pt]{% \begin{pmatrix} a & b \\ c & d \end{pmatrix}}_{\mathstrut A} \times \underbracket[0pt][0pt]{% \begin{pmatrix} x_1 \\ x_2 \end{pmatrix}}_{\mathstrut x} = \underbracket[0pt][0pt]{% \begin{pmatrix} b_1 \\ b_2 \end{pmatrix}}_{\mathstrut b}$
\end{document}


The contents of the labels are top aligned so I've pushed the x label a bit down. Thanks to egreg, now the contents are fixed to the baseline regardless of their height.

-
hmmm interesting abuse :-) –  user1172468 Oct 20 '12 at 22:40
You can say _{\mathstrut x} and similarly for the other two subscripts, so the top alignment wouldn't matter. –  egreg Oct 20 '12 at 22:40
The more I look @ this -- the more I think wicked, wicked, wicked :-) –  user1172468 Oct 20 '12 at 22:42
@user1172468 :) See also egreg's comment for the alignment. I'll update the answer soon. –  percusse Oct 20 '12 at 22:43

Another option is to use \underset as in this answer.

## Code

[Edit: added \usepackage{amsmath}]

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\underset{\begin{array}{c}\\ A \end{array}}% {% \begin{pmatrix} a & b \\ c & d% \end{pmatrix}% }% \underset{\begin{array}{c}\\ x \end{array}}% {% \begin{pmatrix} x_{1} \\ x_{2}% \end{pmatrix}% }=\underset{\begin{array}{c}\\ b \end{array}}% {% \begin{pmatrix} b_{1} \\ b_{2}% \end{pmatrix}% }$
\end{document}


## Output

-

Just to have an overkilling solution with TikZ...

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix,positioning}

\def\vertmathalign{-\the\dimexpr\fontdimen22\textfont2\relax}

\tikzset{rnd delim matrix/.style={
left delimiter=(,right delimiter=),
ampersand replacement=\&, inner sep=1pt,
every node/.style={anchor=base},row sep=0.75ex,
column sep=0.5em,matrix of math nodes,
minimum height=2ex,
}
}

\tikzset{math node/.style={
execute at begin node={$}, execute at end node={$},
text height=1ex,
}
}

\begin{document}

\begin{align}
\begin{tikzpicture}[baseline=\vertmathalign]
\matrix (m1)[rnd delim matrix]{
a \& b \\
c \& d \\
};
\node[math node,below=0.15cm of m1]{A};
\end{tikzpicture}
\begin{tikzpicture}[baseline=\vertmathalign]
\matrix (m2)[rnd delim matrix]{
x_1\\
x_2\\
};
\node[math node,below=0.2cm of m2]{x};
\end{tikzpicture}
=
\begin{tikzpicture}[baseline=\vertmathalign]
\matrix (m3)[rnd delim matrix]{
b_1\\
b_2\\
};
\node[math node,below=0.15cm of m3]{b};
\end{tikzpicture}
\end{align}

\end{document}


The result:

-

In plain TeX I would use \atop:

$${\pmatrix{a &b \cr c &d\cr}\atop A} {\pmatrix{x_1\cr x_2}\atop \mathstrut x} \raise8pt\hbox{=} {\pmatrix{b_1\cr b_2}\atop b}$$
\bye


but I had to manually adjust the position of the equal sign.

-