1

I have several =-aligned equations like this:

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

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

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.

2 Answers 2

6

If you really want all the equality signs centered, consider

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

enter image description here

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}

enter image description here

0

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.


enter image description here

\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{%
   luatexbase.add_to_callback (
   "process_input_buffer", center_eq , "CenterEq" )}}
\newcommand\CenterEqOff{\directlua{%
   luatexbase.remove_from_callback (
   "process_input_buffer", "CenterEq" )}}

\begin{document}
\CenterEqOn
\begin{equation}\begin{split}
  aaa       &= bbbbbb\\
  ccccccccc &= ddd \%
\end{split}\end{equation}
\lipsum[2]
\begin{align}
  e              &= f \\
  adfkjas;fldasj &= ljdfja \\
                 &= djfal;sfjksajfdal;sfj
        \label{eq:last}  % place this instruction on a separate line!
\end{align}

A cross-reference to equation \eqref{eq:last}.
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .