11

There seem to be a whopping align, aligned, alignedat, alignat, xalignat, xxalignat and falign in amsmath / mathtools - some also in there starred version.

I just find sloppy statements like:

When do I use which align environment (best practice)?

What are the exact differences between them?

Why does the environment exist at all (example use case, if applicable)?

Which should I avoid and why?

different align environments

In particular, what are the differences between

  • align and xalignat
  • xxalignat and flalign*
  • alignat* and alignedat

different align environments 2

and what is the semantic difference / different use-case between align* and aligned? When do I use which?

different align environments 3

It appears to me as if align is intended to be used to print independent columns whereas alignat is intended to align dependent columns (e.g. equations [rows] aligned by their operators [columns]).

Thanks a lot!


Appendix

Source:

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools,onlyamsmath}

\newlength{\Short}
\newlength{\LShort}
\newlength{\Long}
\setlength{\Short}{.05\columnwidth}
\setlength{\LShort}{.08\columnwidth}

\newcommand{\env}[2][]{\begin{#2}#1
    \framebox[\Short]{} &= \framebox[\LShort]{} & \framebox[\LShort]{} &= \framebox[\LShort]{} & \framebox[\LShort]{} &= \framebox[\LShort]{}\\
    \framebox[\Short]{} &= \framebox[\Short]{}  & \framebox[\Short]{}  &= \framebox[\Short]{}  & \framebox[\Short]{}  &= \framebox[\Short]{}
\end{#2}}

\newcommand{\Align}[2][]{\paragraph{#2}\env[#1]{#2}}
\newcommand{\mAlign}[2][]{\paragraph{#2}\[\env[#1]{#2}\]}


\begin{document}

\thispagestyle{empty}
\enlargethispage{\baselineskip}

\Align{align*}
\Align{align}

\Align[{3}]{alignat*}
\Align[{3}]{alignat}

\mAlign{aligned}

\mAlign[{3}]{alignedat}

\Align[{3}]{xalignat}
\Align[{3}]{xxalignat}

\Align{flalign*}
\Align{flalign}

\newpage

\Align{align}
\Align[{3}]{xalignat}

\Align[{3}]{xxalignat}
\Align{flalign*}

\Align[{3}]{alignat*}
\mAlign[{3}]{alignedat}

\Align{align*}
\mAlign{aligned}

\end{document}
6
  • You missed multline. I'd say that it is opinion based, you use the tool best suited for whatever you're typesetting. For most of my manuscript editing I tend to use equation for one-liners and align for the rest (never use align for one-liners, trained eyes can spot them in the PDF). Occasionally I'll use gather and alignedat as well. I also use aligned or alignedat` for some constructions and rarely split. The rest I never use (especially not multline and eqnarray)
    – daleif
    Apr 29 at 8:44
  • @daleif I left out multline intentionally. I did non write it explicitly but these are all centering environments. multline is unique in this sense as it left-aligns the first line, right-aligns the last and centers the rest. Adding multline, I would also need to list gather, gather*, gathered, split and possibly others. I am curious about those as well but I thought it might be overkill for the question.
    – Suuuehgi
    Apr 29 at 12:35
  • My gut feeling is that the *ed*-environments are "internal" ones that might be used within other environments but are not intended to be used stand-alone and that the x*-environments are legacy stuff -- so that align, alignat and flalign as well as their starred counterparts remain. But since most of the stuff about LaTeX on the internet is a subjective myth, I'd like to have that confirmed by someone with more experience. And I'm also curious about the history and circumstances of those environments. :)
    – Suuuehgi
    Apr 29 at 12:46
  • 1
    the naming scheme that -ed ones are for alignments to be used within an outer math display is well documented in the amsmath documentation, you don't need "gut feeling" or to believe in myths Apr 30 at 12:56
  • 1
    @Suuuehgi first paragraph of 3.7 is what I had in mind "alignment building blocks" it's actually not as clear as I remembered, but does distinguish full displays (described in the previous section) from the -ed ones which make a term within an equation. They are not in 3.1 as they do no make math displays, they have their own section, 3.7 Apr 30 at 19:25

1 Answer 1

6

amsmath is derived from AMSTeX (amstex.tex) which does not have * forms but otherwise has mostly similar naming, including the x- variants. The environments that start math displays are documented in amsmath.pdf as

%    \begin{environment}{align}
%    \begin{environment}{align*}
%    \begin{environment}{flalign}
%    \begin{environment}{flalign*}
%    \begin{environment}{alignat}
%    \begin{environment}{alignat*}
%    \begin{environment}{xalignat}
%    \begin{environment}{xalignat*}
%    \begin{environment}{xxalignat}
%    The definitions of the various \env{align} environments are quite
%    straight-forward.
%
%    \begin{macrocode}
\newenvironment{alignat}{%
  \start@align\z@\st@rredfalse
}{%
  \endalign
}
\newenvironment{alignat*}{%
  \start@align\z@\st@rredtrue
}{%
  \endalign
}
\newenvironment{xalignat}{%
  \start@align\@ne\st@rredfalse
}{%
  \endalign
}
\newenvironment{xalignat*}{%
  \start@align\@ne\st@rredtrue
}{%
  \endalign
}
\newenvironment{xxalignat}{%
  \start@align\tw@\st@rredtrue
}{%
  \endalign
}
\newenvironment{align}{%
  \start@align\@ne\st@rredfalse\m@ne
}{%
  \math@cr \black@\totwidth@
  \egroup
  \ifingather@
    \restorealignstate@
    \egroup
    \nonumber
    \ifnum0=`{\fi\iffalse}\fi
  \else
    $$%
  \fi
  \ignorespacesafterend
}
\newenvironment{align*}{%
  \start@align\@ne\st@rredtrue\m@ne
}{%
  \endalign
}
\newenvironment{flalign}{%
  \start@align\tw@\st@rredfalse\m@ne
}{%
  \endalign
}
\newenvironment{flalign*}{%
  \start@align\tw@\st@rredtrue\m@ne
}{%
  \endalign
}

Where you can see they are all variants of the same underlying code.

Comparing, say xalignat* and align* You see

\start@align\@ne\st@rredtrue
\start@align\@ne\st@rredtrue\m@ne

so align* is just \xalignat* except -1 is supplied as the number of column pairs, which makes the environment not require a {3} argument for 3 column pairs in your example, it just does the right thing. As such, the x... versions are not really needed and are not documented at all in the user level amslguide.pdf documentation.

As documented, the -ed named environments do not start a math display and must be started within an outer math environment. They have more in common with array or matrix, except that they set their entries with left and right, rather than centred, alignment and use displaystyle rather than textstyle.

6
  • Nice one, +1. But, did you mean amstex.sty (or amstex.tex)?
    – gusbrs
    Apr 30 at 15:37
  • @gusbrs no amstex is amstex.tex (predates latex 2.09) /usr/local/texlive/2022/texmf-dist/tex/amstex/base/amstex.tex (amstex.sty was first version of the merge of that with latex, that became amsmath) Apr 30 at 15:41
  • @DavidCarlisle Yes, I meant what @barbarabeeton mentioned, the last "t". There exists amstext.sty but, if I recall correctly, it's the one which defines the \text macro.
    – gusbrs
    Apr 30 at 15:56
  • @gusbrs ah, sorry. Apr 30 at 16:07
  • 1
    @Suuuehgi as I say above aligned like all environments ending ed does not make a display (so not in the list I showed) it makes a term within an equation, like matrix but with the column alignment like align, matrix is like \begin{array}{ccccc} aligned, is like \begin{array}{rlrlrl} Apr 30 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.