0

In the middle example the space between the $\equiv$ and the right side is wrong. Can I not put the alignment & anywhere I want?

example

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
\begin{align*}
a + b \equiv c\\
x + y \equiv z.
\end{align*}
\begin{align*}
a + b \equiv& c\\
x + y \equiv& z.
\end{align*}
\begin{align*}
a + b &\equiv c\\
x + y &\equiv z.
\end{align*}
\end{document}
  • 2
    The & usually goes before the relation sign that serves as alignment point. – egreg Sep 6 '18 at 12:32
  • 3
    If for some reason, you have to align by the r.h.s., write \equiv {} &. – Bernard Sep 6 '18 at 12:35
2

Can I not put the alignment & anywhere I want?

No, you cannot. As you discovered yourself in the third example, the correct spacing was obtained when you put the alignment tab & before the relation symbol. If you put it after the relation symbol, you get wrong spacing as in your second example.

Why? Let’s use your align* example. In amsmath.dtx we found the following code involving the align family of environments:

\def\align@preamble{%
   &\hfil
    \strut@
    \setboxz@h{\@lign$\m@th\displaystyle{##}$}%
    \ifmeasuring@\savefieldlength@\fi
    \set@field
    \tabskip\z@skip
   &\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
    \ifmeasuring@\savefieldlength@\fi
    \set@field
    \hfil
    \tabskip\alignsep@
}

The most important things to notice are: $\m@th\displaystyle{##}$ and $\m@th\displaystyle{{}##}$. These two lines reveal that when a “right- and left-aligned two-column” pair is created, the left-aligned second column has an empty atom {} inserted at the beginning, and this is how amsmath gets the spacing around relation symbol right (but only if you put the alignment tab before the relation symbol).

Similar implementation goes with the aligned family of environments, the split and multline environments.


I do not encourage the following hack! I consider changing the source code of something as stable as amsmath dangerous and an extremely bad practice. I hope this next example illustrates why amsmath does not add {} to both columns.

Just to show you what would happen if I change the definition of the right-aligned first column:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
%\usepackage{amsfonts}% <- you don't need `amsfonts' if `amssymb' is loaded
\usepackage{amssymb}

% Do not do the following! It is just for this illustration!
\makeatletter
\def\align@preamble{%
   &\hfil
    \strut@
%    \setboxz@h{\@lign$\m@th\displaystyle{##}$}% <- commented out
    \setboxz@h{\@lign$\m@th\displaystyle{##{}}$}% <- inserted here
    \ifmeasuring@\savefieldlength@\fi
    \set@field
    \tabskip\z@skip
   &\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
    \ifmeasuring@\savefieldlength@\fi
    \set@field
    \hfil
    \tabskip\alignsep@
}
\makeatother

\begin{document}
\subsection*{I~do not encourage this hack! This leads to bad coding habits}
\begin{align*}
a + b \equiv c \qquad\qquad & a + b \equiv +1 \\
x + y \equiv z \qquad\qquad & x + y \equiv -1.
\end{align*}
\begin{align*}
a + b \equiv& c \quad \text{Seems fine} & a + b \equiv& +1 \quad \text{Wrong spacing!}\\
x + y \equiv& z                         & x + y \equiv& -1.
\end{align*}
\begin{align*}
a + b &\equiv c \quad \text{This is good} & a + b &\equiv +1 \quad \text{Correct spacing!}\\
x + y &\equiv z                           & x + y &\equiv -1.
\end{align*}
\end{document}

align spacing

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.