The solutions below require up-to-date versions of LaTeX
When I tried to run the solutions below on my own machine I was not able to reproduce their results, but still got unwanted offsets. This was remedied by updating the latest distribution of LaTeX (2018). As pointed out in this comment, this is because
amsmathhas had itsalignedenvironment updated.
Problem
I have several lines in a proof of mine, and I want to align several terms as shown:
Output
I can achieve the following using phantom where needed:
MWE
\documentclass{extarticle}
\usepackage{amsmath,bbm,bm,amssymb,amsthm,mathtools,cleveref,physics,letltxmacro}
% For usage in align environments.
\newcommand\phantomrel[1]{\mathrel{\phantom{#1}}}
\newcommand\phantombin[1]{\mathbin{\phantom{#1}}}
\begin{document}
\begin{align}
A
& = \text{several short lines}\
& = \text{some very long line which takes up most of the width of the page} \
& = \text{several short lines} \
& = B + \mathbb{E}(\abs{a + b + c + d}) \qquad \text{(typically too long for a single line)} \
& \leq B + \mathbb{E}(\abs{a}) \ % Using the triangle inequality.
& \phantomrel{\leq} \phantom{B} + \mathbb{E}(\abs{b}) \
& \phantomrel{\leq} \phantom{B} + \mathbb{E}(\abs{c}) \
& \phantomrel{\leq} \phantom{B} + \mathbb{E}(\abs{d}) \
\end{align}
\end{document}
However, I am weary that this doesn't seem very scalable if I were to find an error and need to change B to a wider set of symbols, and would like to avoid falling into a copy/paste loop.
I am using
phantomrelandphantombinbecause of a previous question of mine
Thinking of a better writing pattern my first two thoughts were:
- Use an
alignedwithin the originalalign. - Use an array.
Using an array?
\begin{align*}
A
& = \text{several short lines}\\
& = \text{some very long line which takes up most of the width of the page} \\
& = \text{several short lines} \\
& = B + \mathbb{E}(\abs{a + b + c + d}) \qquad \text{(typically too long for a single line)} \\
& \leq B
\begin{array}[t]{r}
{} + \mathbb{E}(\abs{a}) \\
{} + \mathbb{E}(\abs{b}) \\
{} + \mathbb{E}(\abs{c}) \\
{} + \mathbb{E}(\abs{d}) \\
\end{array}
\end{align*}
Although this has the + symbols too far offset because of the array margin.
Use aligned?
\begin{align*}
A
& = \text{several short lines}\\
& = \text{some very long line which takes up most of the width of the page} \\
& = \text{several short lines} \\
& = B + \mathbb{E}(\abs{a + b + c + d}) \qquad \text{(typically too long for a single line)} \\
&
\begin{aligned}
\leq B & + \mathbb{E}(\abs{a}) \\ % Using the triangle inequality.
& + \mathbb{E}(\abs{b}) \\
& + \mathbb{E}(\abs{c}) \\
& + \mathbb{E}(\abs{d})
\end{aligned}
\end{align*}
Almost, but the alignment is a bit off and I am not sure why.
Why not just use aligned for the whole thing?
I can't figure out how I would handle the very long lines without some selective use of mathclap (or similar), and would rather keep my use of ampersands to a minimum.






array). Any idea why? – oliversm Oct 19 '18 at 08:48amsmathpackage (which is loaded automatically by themathtoolspackage) was updated. One of the main changes was the behavior of thealignedenvironment. Try inserting\!("negative thinspace) immediately before\begin{aligned}in your code. If this resolves the alignment issue, then your TeX distribution still uses the old version of theamsmathpackage; my recommendation would be for you to update your TeX distribution. – Mico Oct 19 '18 at 09:12