# Aligning multiline equations

When using the multiline environment with the following code

    1. $$E(Y ) = aE(X) + b$$. (5 marks)\par
\begin{multiline}
$$\E(aX+b)&=& \sum_{x}{ax+b)p(x)\\ \sum_{X}(ax\cdot p(x)+b\cdot p(x))\\ \sum_{X}ax\cdot p(x) + \sum_{X}b\cdot p(x)\\ a\underbrace{\left(\sum_{X}X\cdot p(x)\right)}_{E(X)} + b\underbrace{\left(\sum_{X}p(x)\right)}_{1}\\ a\cdot \E(X) + b}$$
\end{multiline}


The equation goes over the width of the pagw, as seen in the screenshot below

I have tried to use the align environment, but it gives me an error saying that the environment cannot be recognised.

Can you help me to resolve this?

The log output file can be seen below

• you surely get an error placing an equation inside multiline? do not use equation (or \par) and use \\  where you want the liebreaksto occur Mar 3 at 15:37
• please don't paraphrase error messages, that makes it impossible to debug. show a small but complete test document (from \documentclass to \end{document} and show the exact error message from the log file. Mar 3 at 15:39
• I have used \\ where I want the line breaks. Mar 3 at 15:41
• equation is always one line Mar 3 at 15:41
• yes multiline is a typo for multline as I wrote in my answer, it is not expected to be dfined. (it is better to show errors as text not as screenshots of an editor summary) Mar 3 at 15:49

As stated in @DaviCarlisle comment below his answer, your equation has sense, if You insert equal signs at begin of each equation:

\documentclass{article}
\usepackage{amsmath}
\newcommand\E{\mathrm{E}}

\begin{document}

1. $$\E(Y ) = a\E(X) + b$$.   (5 marks)
\begin{align*}
\E(aX+b) & = \sum_{x}(ax+b)p(x)\\
& = \sum_{X}\bigl(ax\cdot p(x)+b\cdot p(x)\bigr)
=  \sum_{X}ax\cdot p(x) + \sum_{X}b\cdot p(x)   \\
& = a\underbrace{\biggl(\sum_{X}X\cdot p(x)\biggr)}_{E(X)} +
b\underbrace{\biggl(\sum_{X}p(x)\biggr)}_{1} \\
& = a\cdot \E(X) + b
\end{align*}
\end{document}

\documentclass{article}

\usepackage{amsmath}

\begin{document}

1. $$E(Y ) = aE(X) + b$$. (5 marks)\par
\begin{multiline}
$$\E(aX+b)&=& \sum_{x}{ax+b)p(x)\\ \sum_{X}(ax\cdot p(x)+b\cdot p(x))\\ \sum_{X}ax\cdot p(x) + \sum_{X}b\cdot p(x)\\ a\underbrace{\left(\sum_{X}X\cdot p(x)\right)}_{E(X)} + b\underbrace{\left(\sum_{X}p(x)\right)}_{1}\\ a\cdot \E(X) + b}$$
\end{multiline}
\end{document}


Produces the error

! LaTeX Error: Environment multiline undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.8 \begin{multiline}

?


After any error the pdf output is not intended to be usable.

The environment here is multline (no i) and should not have equation

But multline does not have & alignment so here it seems you want align*

\documentclass{article}

\usepackage{amsmath}
\newcommand\E{\mathrm{E}}
\begin{document}

1. $$E(Y ) = aE(X) + b$$. (5 marks)
\begin{align*}
\E(aX+b) =& \sum_{x}(ax+b)p(x)\\

• I used the form you had, but If I read your example correctly I would have used = on each line (not \quad as I used here) Mar 3 at 15:51
• @RasaiStewart yes I added that to try to make sense of the linebreaks but on looking at the image I think these lines are all equal to the line above so should start &= ? Mar 3 at 15:56
• @RasaiStewart \quad adds 1em horizontal space Mar 3 at 15:57