P.L.
P.L.

Reputation: 11

align enviroment tab and kerning

I have been using common align environment from amsmath and noticed strange behaviour of kerning when placing the & sign from either side of the + sign. Namely assume the following code and the result it produces for me:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{align}
        a&+b\\
        a+&b
    \end{align}
\end{document}

link to picture of output

Is this a bug? If this is intended behaviour, can you please explain why the kerning is different in those cases?

For all it could matter I am using TexStudio 4.0.1 and MikTex (Console version 4.8, all packages updated on 24th Aug 22) to produce the output from the code.

Upvotes: 1

Views: 321

Answers (1)

Celdor
Celdor

Reputation: 2607

I think it's working as expected. The ampersand characters defines a boundary between left and right columns, which in turn are right and left aligned, respectively. Everything to the left is pushed leftwards and everything to the right is pushed rightwards.

Consider the code

\documentclass{article}
\usepackage{amsmath}
\setlength\fboxsep{0pt}
\begin{document}
\begin{align}
  \boxed{a}  \clap{\rule[-3pt]{0.4pt}{12pt}}& + b\\
         a + \clap{\rule[-3pt]{0.4pt}{12pt}}& \boxed{b}
\end{align}
\end{document}

enter image description here

IMO there's the perfect split between two columns. The extra spacing comes from + being an operator so LaTeX does add extra spacing around it.

In your code, there is another issue. An ampersand placed at the right of an operator cancels its status of being the operator. The effect is it's losing expected spacing; the same would happen with =. Adding anything between an operator and & restore its status. Therefore, {} placed right before & is he easiest solution

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
       a & + b \\
   a + {}& b
\end{align}
\end{document}

Upvotes: 0

Related Questions