[Tex/LaTex] Multi-line equation with split

alignamsmathequations

I have the following problem:

enter image description here

Obviously I want the = to be aligned and I need two lines for the equation following the third =.

Also I'm not so sure whether I used the \big{[} and \big{]} commands correctly!?

Code so far as follows:

\documentclass[12pt, a4paper] {article}
\usepackage{amsmath}
\DeclareMathOperator{\var}{var}
\usepackage{mathdesign}
\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}
\begin{equation}
\begin{split}
\vec{V}_i &= E[\boldsymbol{\hat{\vec{\varepsilon}}}^*_i \boldsymbol{\hat{\vec{\varepsilon}}}^*_{i}' \;\;|\;\; \vec{X}^*_i]\\
&= \big{[}[\boldsymbol{\vec{\varepsilon}}^*_i - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)] [\boldsymbol{\vec{\varepsilon}}^*_i - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)]' \;\;|\;\; \vec{X}^*_{i}\big{]}
&= E[\boldsymbol{\vec{\varepsilon}}^*_i \boldsymbol{\vec{\varepsilon}}^*_{i}' - \boldsymbol{\vec{\varepsilon}}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)' \vec{X}^*_{i}' - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i) \boldsymbol{\vec{\varepsilon}}^*_{i}'\\ + \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i) (\hat{\vec{\theta}}_i - \vec{\theta}_i)' \vec{X}^*_{i}' \;\;|\;\; \vec{X}^*_i]\\
&= \vec{I} \sigma^2_{\boldsymbol{\vec{\varepsilon}}^*_{i}} + \vec{X}^*_i (\vec{X}'_i \vec{X}_i)^{-1} \vec{X}^*_{i}' \sigma^2_{\boldsymbol{\vec{\varepsilon}}^*_{i}}.
\label{eq: covariance}
\end{split}
\end{equation}

\end{document}

Best Answer

You can use the multlined environment from mathtools. I also defined an \EV command, that works with a given command (following an example in the mathtools documentation). It has a simple syntax (\EV{A \given B} and gives a correct spacing for the Expected Value, and has delimiters and vertical line that adapt to the contents size in the star version; otherwise, it can take an optional argument (\big, \Big, &c.) for the size. Unfortunately, it doesn't work with line breaks, so the multilined part had to be done by hand.

\documentclass[12pt, a4paper] {article}
\usepackage{mathtools}
\DeclareMathOperator{\var}{var}
\usepackage{mathdesign}
\renewcommand{\vec}[1]{\mathbf{#1}}

\providecommand\given{}
\DeclarePairedDelimiterXPP\EV[1]{E}[]{}{
\renewcommand\given{\nonscript\;\delimsize\vert\nonscript\;\mathopen{}}
#1}
\begin{document}

\begin{equation}
\begin{split}
\vec{V}_i &= \EV*{\boldsymbol{\hat{\vec{\varepsilon}}}^{*}_i \boldsymbol{\hat{\vec{\varepsilon}}^{*} _i}{'}\given \vec{X}^{*}_i}\\
&= \EV[\big]{[\boldsymbol{\vec{\varepsilon}}^*_i - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)] [\boldsymbol{\vec{\varepsilon}}^*_i - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)]' \given \vec{X}^*_{i}}\\
&=\!\begin{multlined}[t]E\bigl[\boldsymbol{\vec{\varepsilon}}^*_i \boldsymbol{\vec{\varepsilon}}^*_{i}{'} - \boldsymbol{\vec{\varepsilon}}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i)' \vec{X}^*_{i}{'} - \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i) \boldsymbol{\vec{\varepsilon}}^*_{i}{'}\\
+ \vec{X}^*_i (\hat{\vec{\theta}}_i - \vec{\theta}_i) (\hat{\vec{\theta}}_i - \vec{\theta}_i)' \vec{X}^*_{i}{'} \;\big\vert\; \vec{X}^*_i\bigr]
\end{multlined}\\
&= \vec{I} \sigma^2_{\boldsymbol{\vec{\varepsilon}}^*_{i}} + \vec{X}^*_i (\vec{X}'_i \vec{X}_i)^{-1} \vec{X}^*_{i}{'} \sigma^2_{\boldsymbol{\vec{\varepsilon}}^*_{i}}.
\label{eq: covariance}
\end{split}
\end{equation}

\end{document} 

enter image description here