# Alignment within the equation environment

This is the state of affairs:

The goal is to horizontally center the symbols over their expressions within an equation environment. So A is centered over the first matrix, x centered over the first vector and b centered over the final vector.

MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$$\begin{split} % {\bf{A}} x & = b \\ % \left[ \begin{array}{cc} 1 & 0 \\ 0 & 1 \\ \end{array} \right] % \left[ \begin{array}{c} x_1 \\ x_2 \end{array} \right] &= % \left[ \begin{array}{c} b_1 \\ b_2 \end{array} \right] % \end{split}$$

\end{document}


These posts do not seem to offer readily a solution:

Complicated alignment within multiline equation

Aligning Multiline Matrix Equations

Aligning equations with text with alignat

Difference between align and alignat environments

TeXShop 3.58, distribution TeXLive - 2015

With array you can obtain the following:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$$\arraycolsep=1pt \begin{array}{cccc} \mathbf{A} & \mathbf{x} & = & \mathbf{b} \\ \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ \end{bmatrix} & \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} & = & \begin{bmatrix} b_1 \\ b_2 \end{bmatrix} \end{array}$$
\end{document}


Considered is @Mico comment below. Typographical more correct result you will get if in matrices be restored default \arraycolsep value (6pt). This can be done with adding

\AtBeginEnvironment{bmatrix}{\arraycolsep=6pt}


in document preamble. If you still have an older LaTeX installation, you also need to load \etoolbox package:

\documentclass{article}
\usepackage{mathtools}

%\usepackage{etoolbox} % activate if you have an older LaTeX instalation
\AtBeginEnvironment{bmatrix}{\arraycolsep=6pt}

% for show just the equation, don't use in the real document  ...
\usepackage[active,displaymath,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}

$$\arraycolsep=1pt \begin{array}{cccc} \mathbf{A} & \mathbf{x} & = & \mathbf{b} \\ \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ \end{bmatrix} & \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} & = & \begin{bmatrix} b_1 \\ b_2 \end{bmatrix} \end{array}$$

\end{document}


• +1. I think it would add a nice touch to locally restore the default value of \arraycolsep for the first of the three bmatrix environments.
– Mico
Commented Feb 20, 2022 at 7:27
• @Mico, you are right. For example, it can be done ba adding \AtBeginEnvironment{bmatrix}{\arraycolsep=6pt} in document preamble. Will add to answer ASAP. Commented Feb 20, 2022 at 7:33
• @Mico, now is done. Commented Feb 20, 2022 at 8:09

The obvious choice is array, but with some tricks to avoid guessing the spaces.

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{array}

\newenvironment{lsarray}[1][c]% ls for 'linear system'
{\begin{array}[#1]{@{} c @{} c @{} >{{}}c<{{}} @{} c @{}}}
{\end{array}}

\begin{document}

Centered equation number:
$$\begin{lsarray} \mathbf{A} & \mathbf{x} & = & \mathbf{b} \\ \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} & \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} & = & \begin{bmatrix} b_1 \\ b_2 \end{bmatrix} \end{lsarray}$$

Bottom equation number:
$$\begin{lsarray}[b] \mathbf{A} & \mathbf{x} & = & \mathbf{b} \\ \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} & \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} & = & \begin{bmatrix} b_1 \\ b_2 \end{bmatrix} \end{lsarray}$$

\end{document}


The twocolumn option is used just to make a less wide picture, in order to better see the equation number placement in the two cases.