# [Tex/LaTex] Weird Behavior of Math mode in beamer

alignbeamermath-mode

I wanted to use align* environment but it's somehow not working. It's working with regular  but the problem is then i have to customize formatting with \hspace and \vspace which defeats the purpose of TeX.

It seems to be a straight forward question. Could be a bug in TeX. Cause there are no typos. I have gone over the slide many times. The code is given below and the output slide is also shown underneath the code.

\begin{frame}{Best Linear Predictor}
\begin{itemize}

\item $\min \limits_{\alpha,\beta} E(Y - \alpha - \beta X)^2$\\
\item Expanding the squared terms and taking the expectations individually we get the    following:
\bigskip

$S = E(Y)^2 +\alpha ^2 + \beta ^2 E(X)^2 - 2\alpha E(Y) - 2\beta E(XY) + 2 \alpha \beta E(X)$\\

\item First order Conditions:\\
\bigskip
$\frac{\partial S}{\partial \alpha} = 2\alpha - 2 E(Y) + 2\beta E(X)=0$

$\frac{d S}{d \beta} = 2\beta E(X)^2 - 2 E(XY) + 2 \alpha E(X)=0$

\item Solving the above equations simultaneously for $\alpha$ and $\beta$ and denoting the optimal values by $\alpha*$ and $\beta*$ , we get,\\
$\beta^* = \frac{Cov(X,Y)}{V(X)}$\\
and \\
$\alpha^* = E(Y) - \frac{Cov(X,Y)}{V(X)} E(X)$
\end{itemize}
\end{frame}


#### Best Answer

Try this:

\documentclass{beamer}

\setbeamertemplate{section in toc}{\hspace*{1em}\inserttocsectionnumber.~\inserttocsection\par}
\setbeamertemplate{subsection in toc}{\hspace*{2em}\inserttocsectionnumber.\inserttocsubsectionnumber.~\inserttocsubsection\par}

\begin{document}

\begin{frame}[allowframebreaks]{Best Linear Predictor}
\begin{itemize}
\item $\min \limits_{\alpha,\beta} E(Y - \alpha - \beta X)^2$\\
\item Expanding the squared terms and taking the expectations individually we get the    following:
$S = E(Y)^2 +\alpha ^2 + \beta ^2 E(X)^2 - 2\alpha E(Y) - 2\beta E(XY) + 2 \alpha \beta E(X)$
\item First order Conditions:
\begin{align*}
\frac{\partial S}{\partial \alpha} &= 2\alpha - 2 E(Y) + 2\beta E(X)=0 \\
\frac{d S}{d \beta} &= 2\beta E(X)^2 - 2 E(XY) + 2 \alpha E(X)=0
\end{align*}
\item Solving the above equations simultaneously for $\alpha$ and $\beta$ and denoting the optimal values by $\alpha*$ and $\beta*$ , we get,
\begin{align*}
\beta^* &= \frac{Cov(X,Y)}{V(X)} \\
\intertext{and}
\alpha^* &= E(Y) - \frac{Cov(X,Y)}{V(X)} E(X)
\end{align*}
\end{itemize}
\end{frame}

\end{document}


As you can see, align* works as expected. I made some other changes using $...$ for displayed single-line expressions and using \intertext in the last align* (\shortintertext from the mathtools package could also have been used and produces better results regarding the vertical space).

On a side note, your frame has too much information: either use two frames or pass [allowframebreaks] to the frame (as in my example), to have a better spatial distribution.