# Spacing problem with aligned nested in an align environement

This minimal example

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
A
&\leq
\begin{aligned}[t]
&\int \text{first part of a long expression}
\\& \times \text{second part of the long expression}
\end{aligned}
\\&\leq \int \text{shorther expression}
\end{align*}
\end{document}


gives

The two integral signs are not aligned because there is too much space before the first ones (or equivalently, before the aligned environment).

How can I get the correct horizontal space before the first integral sign?

• I don't get it. I guess that would just create more space... which is not what I want. – Gilles Bonnet Jul 27 '16 at 15:46
• no. I just tested it. They are both shifted to the right but don't get aligned. – Gilles Bonnet Jul 27 '16 at 15:51
• There is a "bug" in aligned, whenever you what to use it like this remember to use \! \begin{aligned}.... this removes the added space in front of aligned – daleif Jul 27 '16 at 15:53
• @daleif Good to know. Adding \! solved the problem. – Gilles Bonnet Jul 27 '16 at 15:55
• Related/duplicate: tex.stackexchange.com/questions/98482/… – egreg Jul 27 '16 at 17:58

In general whenever aligned is used when there is "something" is front for it to align with, then always use

\! \begin{aligned} ....


This removes the spacing that is inserted at the start of aligned

Edit: there seems to be another issue at play, if the contents of aligned starts with & then there is also spacing issues. The problem and a fix can be seen in this MWE:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
A
&\leq\rlap{\raisebox{-7em}[0pt][0pt]{\rule{0.4pt}{8em}}}
\!
\begin{aligned}[t]
&\int
\end{aligned}
\\
&\leq
\!\begin{aligned}[t]
\! &\int
\end{aligned}
\\
&\leq \int
\end{align*}
\end{document}


• It should be &\!\int; there is an implicit {} after &, which makes TeX insert a thin space between the empty ordinary atom and the operator atom. – egreg Jul 27 '16 at 18:02

You can avoid the aligned, in this case, by using split:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\begin{split}
A&\leq \int \text{first part of a long expression} \\
& \qquad\times \text{second part of the long expression}
\end{split}
\\
&\leq \int \text{shorther expression}
\end{align*}
\end{document}


The alternative with aligned is

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
A&\leq
\!\begin{aligned}[t]
&\!\int \text{first part of a long expression} \\
&\quad\times \text{second part of the long expression}
\end{aligned}
\\
&\leq \int \text{shorther expression}
\end{align*}
\end{document}


One \! is necessary in front of aligned, see Why is there a \, space at the beginning of the "aligned" environment?; another one is needed between & and \int, because after & there is an implicit {} that forces a thin spaces between it and \int, which is an operator atom.