# Align to center

I want to align some equations to the equal signs, so I wrote this:

\begin{align}
-3z &=-9\\
z &= 3\\
-3y-3*3 &= 3\\
y &=-4\\
2x+8*(-4)+4*3 &= 2\\
x &=11
\end{align}


However, because one equation is much longer than the others, all the equations appear somewhat at the right of the page:

How can I make the equal signs appear in the middle while still aligning all the equations to them?

A simple approach would be to duplicate the contents of the widest entry (either left or right) on the opposite side, accommodating for some overlap:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\lipsum[2]
\begin{align*}
-3z &= -9 \\
z &=  3 \\
-3y-3*3 &=  3 \\
y &= -4 \\
2x+8*(-4)+4*3 &=  2 \\
x &= 11
\end{align*}
\lipsum[2]
\begin{align*}
-3z &= -9 \\
z &=  3 \\
-3y-3*3 &=  3 \\
y &= -4 \\
2x+8*(-4)+4*3 &=  \rlap{2}\phantom{2x+8*(-4)+4*3} \\
x &= 11
\end{align*}
\lipsum[2]
\end{document}


Alternatively, if you're not concerned about numbering the equations, then you can use the following construction:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{array}% http://ctan.org/pkg/array
\newsavebox{\mymathbox}
\newcolumntype{R}{>{\begin{lrbox}{\mymathbox}$}r<{$\end{lrbox}\llap{\usebox{\mymathbox}}}}%
\newcolumntype{L}{>{\begin{lrbox}{\mymathbox}$}l<{$\end{lrbox}\rlap{\usebox{\mymathbox}}}}%
\begin{document}
\lipsum[2]
\begin{align*}
-3z &= -9 \\
z &=  3 \\
-3y-3*3 &=  3 \\
y &= -4 \\
2x+8*(-4)+4*3 &=  2 \\
x &= 11
\end{align*}
\lipsum[2]
$\renewcommand{\arraystretch}{1.2} \begin{array}{R@{{}={}}L} -3z & -9 \\ z & 3 \\ -3y-3*3 & 3 \\ y & -4 \\ 2x+8*(-4)+4*3 & 2 \\ x & 11 \end{array}$
\lipsum[2]
\end{document}


This constructs an align* in the form of an array and places the contents on either side of the equal sign in a zero-width box. Consequently, then equations seem centred based on =.

Note that \rlap and \llap uses \makebox, which inserts its contents in text mode. Hence the switch back to math mode via \$ in the automated construction of the L and R column types.

• This doesn't use \displaystyle. When using \displaystyle though, no spacing is added to "tall" entries Commented Mar 31, 2020 at 21:38

I faced a similar problem, but I also wanted to place my final (longer) equation in a box. For boxes in align I used \Aboxed from mathtools. Using the concept from the solution by @Werner above, I found a solution for a center, aligned around '=', boxed equation, which is to place on each side of the equation the text of the other side as \phantom text. That way, the equation can become symmetrical, without using \rlap which messes with the box.

I know this is not exactly what the original post asked for, but I think it would be a very useful addition, since there aren't many posts available discussing the center aligned concept.

Also, I have included, as an extra, a simple way to increase \Aboxed padding, which I could not find anywhere online. The idea is to use one 0-widht-rule for y padding, and two 0-height-rules for x padding. The offset should be placed at minus half the font size, in my case that is 12pt/2=-6pt.

As for the y padding, 20pt occured because I want 4pt above, and for pt below. That gives me 4pt+4pt+12pt = 20pt, where 12pt is the font size.

Here is my MWE:

\documentclass[12pt]{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{mathtools}                          % for Aboxed, to box in alignat environment

\begin{document}
\lipsum[2]
\begin{align*}
-3z &= -9 \\
z &=  3 \\
-3y-3*3 &=  3 \\
y &= -4 \\
2x+8*(-4)+4*3 &=  2 \\
x &= 11
\end{align*}
\lipsum[2]

\begin{align}
-3z &= -9\nonumber \\
z &=  3\nonumber \\
-3y-3*3 &=  3\nonumber \\
y &= -4\nonumber \\
\phantom{2\implies} \Aboxed{\rule[-6pt]{4pt}{0pt}2x+8*(-4)+4*3 &=\rule[-6pt]{0pt}{20pt}2\rule[-6pt]{4pt}{0pt}}\phantom{2x+8*(-4)+4*3 \implies}
\end{align}

\end{document}


And here is the result I wanted to achieve: