Aligning aligned equations

I have a list of equations and some of which have multiple steps which I have managed to align in their individual environments. But I would like each set of equations to also align by "=", while the comments to the right of the equations also stay aligned with eachother.

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}
\begin{document}

\begin{align*} \tag{a}
Y = f(x_0) + \epsilon_0
&& \text{By assumptions}
\end{align*}
\begin{align*} \tag{c}
E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big]
&& \text{By (a)}
\\& = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
&& \text{By Linearity}
\\&= E\big[f(x_0)\big]
&& \text{By Expectation of $\epsilon$}
\end{align*}
\begin{align*} \tag{e.i}
&E\big[f(x_0)] = f(x_0)
&& \text{As $x_0$ is fixed and deterministic}
\\&\text{$f(x_0)$ is constant.} \tag{e.ii}
\\&\text{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{align*}

\end{document}


I am still learning LateX so I'm sorry if this is obvious. I would really appreciate any help and don't be afraid to explain minor steps as this really helps my understanding! Thank you in advance for your time and help.

• Is the &\text{$f(x_0)$ is constant.} a comment or an equation? Commented Dec 29, 2017 at 22:50
• You also can upvote in all answers. :-) Commented Dec 30, 2017 at 2:57

In order to maintain alignment throughout each equation set, considering using the same align structure:

\documentclass{article}

\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{align}
Y &= f(x_0) + \epsilon_0
&& \text{Assumption} \tag{a}\label{eq:a} \\
E\bigl[ Y \bigr] &= E\bigl[ f(x_0) + \epsilon_0 \bigr]
&& \text{by \eqref{eq:a}} \tag{c} \\
&= E\bigl[ f(x_0) \bigr] + \cancel{E\bigl[ \epsilon_0 \bigr]}
&& \text{by linearity} \notag \\
&= E\bigl[ f(x_0) \bigr]
&& \text{by expectation of $\epsilon$} \notag \\
E\bigl[ f(x_0) \bigr] &= f(x_0)
&& \text{$x_0$ is fixed \& deterministic} \tag{e.i} \\
\makebox[0pt][l]{$f(x_0)$ is constant.}
\phantom{E\bigl[ f(x_0) \bigr]} \tag{e.ii} \\
\makebox[0pt][l]{$f(x_0)$ and $\hat{f}(x_0)$ are independent.}
\phantom{E\bigl[ f(x_o) \bigr]} \tag{e.iii}
\end{align}

\end{document}


Setting the last two lines in zero-width boxes provides a little extra room since they don't have descriptions on the right.

You can use alignat and a small trick for the last two lines.

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{alignat*}{2}
\tag{a}
Y &= f(x_0) + \epsilon_0
\\
\tag{c}
E[Y] & = E[f(x_0)+\epsilon_0]
&& \text{By (a)}
\\
& = E[f(x_0)] + \cancel{E[\epsilon_0]}
&& \text{By Linearity}
\\
& = E[f(x_0)]
&& \text{By Expectation of $\epsilon$}
\\
\tag{e.i}
E[f(x_0)] & = f(x_0)
&& \text{As $x_0$ is fixed and deterministic}
\\
\tag{e.ii}
&\settowidth{\dimen0}{$E[f(x_0)]$}
\makebox[0pt][l]{\hspace{-\dimen0}$f(x_0)$ is constant.}
\\
\tag{e.iii}
&\settowidth{\dimen0}{$E[f(x_0)]$}
\makebox[0pt][l]{\hspace{-\dimen0}$f(x_0)$ and $\hat{f}(x_0)$ are independent.}
\end{alignat*}

\end{document}


I removed all \big commands that don't seem that useful. If you prefer larger brackets, they should be like E\bigl[Y\bigr] so the brackets will have their proper nature of fences.

I'm not sure the last three equatiions should be aligned on the = sign, so I propose two slightly different layouts, based on alignat*:

\documentclass[11pt]{article}
\usepackage{mathtools}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{alignat*}{3} \tag{a}
& & Y & = f(x_0) + \epsilon_0
& & \text{by assumptions} \\
& & E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big]\tag{c}
& & \text{by (a)} \\
& & & = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
& \qquad & \text{by linearity} \\
& & & = E\big[f(x_0)\big]
& & \text{by expectation of $\epsilon$} \\[1.5ex]
& \mathrlap{E\big[f(x_0)] = f(x_0)}
& & & & \text{as $x_0$ is fixed and deterministic}\tag{e.i} \\
& \rlap{$f(x_0)$ is constant.} \tag{e.ii} \\
& \rlap{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{alignat*}

\begin{alignat*}{3} \tag{a}
Y & = & & f(x_0) + \epsilon_0
& & \text{by assumptions} \\
E\big[Y\big] & = {} & & E\big[f(x_0)+\epsilon_0\big]\tag{c}
& & \text{by (a)} \\
& = {} & & E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
& \qquad & \text{by linearity} \\
& ={} & & E\big[f(x_0)\big]
& & \text{by expectation of $\epsilon$} \\[1.5ex]
& & & \mathrlap{E\big[f(x_0)] = f(x_0)}
& & \text{as $x_0$ is fixed and deterministic}\tag{e.i} \\
& & & \rlap{$f(x_0)$ is constant.} \tag{e.ii} \\
& & & \rlap{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{alignat*}

\end{document}


Something like that?

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}
\begin{document}

\begin{align*}
\tag{a} Y &= f(x_0) + \epsilon_0 && \text{By assumptions}\\[\bigskipamount]
\tag{c} E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big] && \text{By (a)}\\
& = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]} && \text{By Linearity}\\
&= E\big[f(x_0)\big] && \text{By Expectation of $\epsilon$}\\[\bigskipamount]
\tag{e.i} E\big[f(x_0)] &= f(x_0) && \text{As $x_0$ is fixed and deterministic}\\
\text{$f(x_0)$}\ &\text{is constant.} \tag{e.ii}\\
\text{$f(x_0)$}\ &\text{and}\ \text{$\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{align*}

\end{document}


\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{align*}
Y            & = f(x_0) + \epsilon_0 & & \text{By assumptions} \tag{a} \\[2ex]
E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big] & & \text{By (a)} \tag{c} \\
& = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]} & & \text{By Linearity} \\
& = E\big[f(x_0)\big] & & \text{By Expectation of $\epsilon$} \\[2ex]
E\big[f(x_0)] & = f(x_0) \tag{e.i} & &    \text{As $x_0$ is fixed and deterministic} \\
& \phantom{xx} f(x_0) \text{ is constant.} \tag{e.ii} \\
& \phantom{xx} f(x_0) \text{ and } \hat{f}(x_0) \text{ are independent.} \tag{e.iii}
\end{align*}

\end{document}