# Multiple alignments in flalign within text

I know there are some threat about multuple alignments. However, I couldnt find a solution to my simple problem. Here is a short reproducible example:

\documentclass[a5paper,oneside]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}

\begin{document}
\begin{flalign*}
MSPE &= E[(y_{0}-\hat{f}(x_0))^2|X=x_0] \\
&= E[y_{0}^2] +E[\hat{f}(x_0)^2]-E[2y_{0}\hat{f}(x_0)] \\
&= Var[y_{0}] + E[y_{0}]^2 + Var[\hat{f}(x_0)] + E[\hat{f}(x_0)]^2 -E[2y_{0}\hat{f}(x_0)] \\
& \textnormal{Text should be left aligned unter the word MSPE}\\
&= Var[y_{0}] + Var[\hat{f}(x_0)] + (f(x)^2 - E[2y_{0}\hat{f}(x_0)]+ E[\hat{f}(x_0)]^2)
\end{flalign*}

\end{document}


The line with the text should be aligned under the word "MSPE" and all other equations that follows under

\textnormal{Text should be left aligned unter the word MSPE}


should be set normaly with &=

A simple shortintertext from mathtools should be enough (b.t.w. needless to load amsmath if you load mathtools). Depending on your real margins, you might have to split some lines. I also defined Var as a math operator, to have it upright, with a proper spacing:

\documentclass[a5paper,oneside]{book}
\usepackage{geometry}

\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\DeclareMathOperator{\Var}{Var}

\begin{document}

\begin{flalign*}
MSPE &= E[(y_{0}-\hat{f}(x_0))^2|X=x_0] \\
&= E[y_{0}^2] +E[\hat{f}(x_0)^2]-E[2y_{0}\hat{f}(x_0)] \\
&= \Var[y_{0}] + E[y_{0}]^2 + \Var[\hat{f}(x_0)] + E[\hat{f}(x_0)]^2 -E[2y_{0}\hat{f}(x_0)] \\
\shortintertext{Text should be left aligned unter the word MSPE}
&= \Var[y_{0}] + \Var[\hat{f}(x_0)] + (f(x)^2 - E[2y_{0}\hat{f}(x_0)]+ E[\hat{f}(x_0)]^2)
\end{flalign*}

\end{document}


• there's also \intertext already in amsmath. the text here isn't really "short". – barbara beeton Jul 18 '18 at 17:56