# How to align multiple separate equations by equal sign to center of page

I have several =-aligned equations like this:

$$\begin{split} a &= b b &= c \end{split}$$

$$\begin{split} foo &= x bar &= y baz &= z \end{split}$$


However, when it shows up it looks essentially like this:

        a = b
b = c
... content
foo = x
bar = y
baz = z


The equal signs are not aligned across different equation blocks.

Wondering if there is a way to:

1. Align them to each other.
2. Align them to the center of the page.

If you really want all the equality signs centered, consider

\documentclass{article}
\usepackage{mathtools}
\usepackage{lipsum}
\usepackage{tikz}% just for illustration
\begin{document}
$$\begin{split} \mathllap{a} &= \mathrlap{b}\\ \mathllap{b} &= \mathrlap{c} \end{split}$$
\lipsum[1]
$$\begin{split} \mathllap{foo} &= \mathrlap{x}\\ \mathllap{bar} &= \mathrlap{y}\\ \mathllap{baz} &= \mathrlap{z} \end{split}$$
\tikz[remember picture,overlay]{\draw[red](current page.north)--(current page.south);}
\end{document}


The TikZ and lipsum stuff are just for illustration.

And depending on how long "content" is, you may also use

\documentclass{article}
\usepackage{lipsum}
\usepackage{mathtools}
\begin{document}
\begin{align*}
a &= b\\
b &= c\\
\intertext{\lipsum[1]}
foo &= x\\
bar &= y\\
baz &= z
\end{align*}
\end{document}


Here's a LuaLaTeX solution. In essence, it automates the insertion of the \mathllap and \mathrlap instructions used in @marmot's answer.

For this automated procedure to succeed, the lines of input have to satisfy two main requirements:

• On any line that contains an &= particle, this particle must be both preceded and followed by whitespace. I.e., aaa &= bbb will be recognized and processed, but aaa&=bbb will not. And, there must be no whitespace between & and =.

• The lines that contain &= particles must contain both the full left-hand and right-hand material of the equation in question -- and nothing else. For instance, any \label instructions, and any and all comments, must occur on the lines that precede or follow an equation line.

Hopefully, these two input requirements aren't too burdensome.

The code below consists of (a) a Lua function that does the actual work and (b) two LaTeX macros, called \CenterEqOn and \CenterEqOff, to enable and disable, respectively, the operation of the Lua function.

A final comment: Of course, this entire approach can only really succeed if the material both to the left and to the right of the = symbols never exceeds about 0.4\textwidth. If the material is longer than that, it'll protrude into the left-hand and/or right-hand margins.

\documentclass{article}
\usepackage{lipsum}    % filler text
\usepackage{mathtools} % for '\mathllap' and \mathrlap'
\usepackage{luacode}   % for 'luacode' environment
\begin{luacode}

function center_eq ( s )
if s:find ( "%s&=%s" ) then
s = s:gsub ( "^(.-)&=(.-)(\\?\\?)\$",
"\\mathllap{%1}&=\\mathrlap{%2}%3" )
end
return s
end

\end{luacode}
\newcommand\CenterEqOn{\directlua{%
"process_input_buffer", center_eq , "CenterEq" )}}
\newcommand\CenterEqOff{\directlua{%
luatexbase.remove_from_callback (
"process_input_buffer", "CenterEq" )}}

\begin{document}
\CenterEqOn
$$\begin{split} aaa &= bbbbbb\\ ccccccccc &= ddd \% \end{split}$$
\lipsum[2]
\begin{align}
e              &= f \\