2

I am having trouble centering the entries within two align environments w.r.t =. I tried the solutions suggested in this post. The problem still persists. The following code is borrowed from the same post with some modifications:

\documentclass[12pt,english]{article}
\usepackage{mathtools}

\begin{document}

\begin{align}
    n&=n(ak_1+bl_1)
\end{align}
words
\begin{align}
    n&=ak_n+bl_n\\
    &=ak_n+abx+bl_n-abx
\end{align}
more words

\end{document}

The output:

enter image description here

As apparent from the output, equations (2) and (3) are not center aligned unlike (1). How to fix this?

Edit

The solutions as per this post involve combining two align environments into one. But, sometimes this cannot be done under certain instances for e.g. if a section comes in between two align environments or if lot of text is placed between two align environments.

2
  • 3
    The two sets of equations are centered. Please, specify more clearly what your problem is. Note however, that there is no need whatsoever to “align the equals signs” across the document. It would serve no purpose except in helping to make very unbalanced displays.
    – egreg
    Commented Nov 5, 2021 at 7:53
  • 3
    note that centering an equation means the same space to the left and right not that the = is in the centre. So the output you show is the expected output and would match the output in most publications that use centred equations. Commented Nov 5, 2021 at 7:57

2 Answers 2

4

I must confess to not "getting" the typographic use case for wishing to align the = symbols across two align environments that are separated by a major structural element of the document, such as a section-level header (or any level of sectioning header, really).

However, if you really, truly must perform this alignment of the = symbols, I can think of at least two ways of doing so; both are illustrated below.

  • The first involves measuring the longest right-hand side element in the lower align environment and using this length information to create a \parbox for the material on one of the right-hand side elements in the upper align environment.

  • The second involves using a single align environment and placing the \section directive inside an \intertext wrapper. Yes, this actually works, although it seems mighty strange.

The second method may seem easier to implement. However, the first provides more typographic flexibility, such as allowing a page break to occur right above the section header. ("A page break before a sectioning header? What a concept!", Yacov Smirnoff might exclaim.) Another advantage of the first method is the more natural looking amount of whitespace above the section header.

enter image description here

\documentclass[12pt]{article}
\usepackage{mathtools}
\newlength\mylen
\settowidth\mylen{$\displaystyle ak_n+abx+bl_n-abx$}

\begin{document}

%% Solution 1

\noindent
words
\begin{align}
    n&=\parbox{\mylen}{$\displaystyle n(ak_1+bl_1)$}
\end{align}
\section{First random section title}
\begin{align}
    n&=ak_n+bl_n\\
     &=ak_n+abx+bl_n-abx
\end{align}
more words


\bigskip
\hrule
\bigskip

%% Solution 2

\noindent
words
\begin{align}
    n&=n(ak_1+bl_1)
\intertext{\section{Second random section title}}
    n&=ak_n+bl_n\\
     &=ak_n+abx+bl_n-abx
\end{align}
more words
\end{document}
2

Using the general \noalign to insert vertical material in-between lines of alignment seems to work in this particular case, although I don't think it is officially supported.

edit: This is a bad idea because it doesn't take care of the penalties lineskips, the \intertext macro can do a similar thing as campa mentioned

\documentclass{article}
\usepackage{mathtools}
\begin{document}

words
\begin{align}
    n&=\displaystyle n(ak_1+bl_1) \\
\noalign{%
    \vskip\belowdisplayskip \section{First random section title}
    \vskip\abovedisplayskip
}
    n&=ak_n+bl_n \\
     &=ak_n+abx+bl_n-abx
\end{align}
more words

\end{document}

output

1
  • 2
    It's not directly supported but that's more or less what \intertext does: it's a \noalign plus some penalties (and wraps everything further in a \vbox).
    – campa
    Commented Nov 5, 2021 at 9:40

You must log in to answer this question.

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