0

When using the multiline environment with the following code

    1. \(E(Y ) = aE(X) + b\). (5 marks)\par
\begin{multiline}
\begin{equation}
\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{equation}
\end{multiline}

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

enter image description here

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 enter image description here

6
  • 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
  • 3
    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
  • 1
    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

2 Answers 2

4

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

enter image description here

\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}
1
\documentclass{article}

\usepackage{amsmath}

\begin{document}

    1. \(E(Y ) = aE(X) + b\). (5 marks)\par
\begin{multiline}
\begin{equation}
\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{equation}
\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*

enter image description here

\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)\\
&\quad\sum_{X}(ax\cdot p(x)+b\cdot p(x))\\
&\quad\sum_{X}ax\cdot p(x) + \sum_{X}b\cdot p(x)\\
&\quad a\underbrace{\left(\sum_{X}X\cdot p(x)\right)}_{E(X)} + b\underbrace{\left(\sum_{X}p(x)\right)}_{1}\\
&\quad a\cdot \E(X) + b
\end{align*}
\end{document}
4
  • 2
    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
  • What does \quad do? Mar 3 at 15:55
  • @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
  • 1
    @RasaiStewart \quad adds 1em horizontal space Mar 3 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.