# Unmatching symbols with the alignat environment

I have the following:

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

\begin{alignat*}{2}
&|a-b| & < c\\
-c & < a-b & < c
\end{alignat*}

\end{document}


which produces this:

I tried the align environment at first, but it produced large whitespaces and upon a quick search I found to use the alignat environment instead. However, here the equations don't match up. How could it be fixed?

Using TABstacks, is something like this what you want?

\documentclass{article}
\usepackage{tabstackengine}
\TABstackMath
\setstacktabulargap{0pt}
\TABbinary
\begin{document}
$\tabularCenterstack{rcl}{ &\vert a-b\vert & < c\\ -c <& a-b & < c }$
\end{document}


In this particular case, but not in general, a \tabbedCenterstack could also be used to achieve the same result:

\documentclass{article}
\usepackage{tabstackengine}
\TABstackMath
\TABbinary
\begin{document}
$\tabbedCenterstack{ &\vert a-b\vert & < c\\ -c <& a-b & < c }$
\end{document}


The OP asks if the amsmath environments can be used exclusively. Here is something, but it uses a shoehorn to make it fit unnaturally

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

\begin{alignat*}{3}
&|&a-b&| & {}< c\\
-c  <& &a-b& & {}< c
\end{alignat*}

\end{document}


• That would work indeed, but is there a way to do it using only the align/alignat (or similar) environments? – user154989 Mar 31 '17 at 0:51
• @user154989 See the suffix to my answer. – Steven B. Segletes Mar 31 '17 at 1:07

Essentially you want the width of |a-b| to match that of a-b. This is achievable via eqparbox's \eqmakebox[<tag>][<align>]{<stuff>}, setting <stuff> with the same <tag> using the maximum width across all <tag>s. The default <align>ment is centred:

\documentclass{article}

\usepackage{amsmath,eqparbox}

\begin{document}

\begin{align*}
\eqmakebox[abs]{$\lvert a - b \rvert$} & < c \\
-c <        \eqmakebox[abs]{$a - b$}        & < c
\end{align*}

\end{document}


alignat processes elements in groups of two: l&r & l&r and doesn't leave any space between the groups. what you need to do to fix this, since you have no left-hand side to the second "group", is to double the second &. you also need to add an empty group after the double && since at the beginning of the first element of a group there is no automatic recognition of an operator or relation, hence the spacing will not be correct.

i also didn't understand why align wasn't suitable -- if only one alignment point is used, there shouldn't be any large spaces. (the only reason i could think of was that you want a special alignment that isn't fully described.) anyhow, i've included an example with align as well as with alignat.

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

\begin{alignat*}{2}
& |a-b| && {} < c\\
-c & < a-b && {} < c
\end{alignat*}

\begin{align*}
|a-b| & < c\\
-c < a-b & < c
\end{align*}

\end{document}


There are similar questions to this which were already answered. See for example. See a more complex example here. It looks like the solution with \tabularCenterstack is the most stable (but I did not test if the spacing is right around the \le sign.

But, in case you insist to use alignat*, remember that in \begin{alignat*}{2} you should have three & symbols in each line. In general, with \begin{alignat*}{n} you should have 2n-1 symbols &, so that you have 2n spaces to type (including the beginning, the end and those in between the &s). The spaces correspond to the lefthandside and the righthandside of nequations respectively.

The problem is that alignat* is not meant to produce centered alignment in any of those columns (they alternate between right-aligned and left-aligned). In case all terms in a particular column are equal, usually you can fake centered alignment by correctly position the &s. Sometimes you need to use {} after the equality/inequality sign to have the correct spacing. On other cases, you may try to use some tricks, like the \eqmakebox when both terms have the same size, but the solution will not scale well unless you use some trick of Wener.