# How to split an equation inside two columns frame of beamer?

I want to enter the equation in two columns frame of beamer. This is my original equation:

\begin{gather*}
\begin{split}
J=C(\sum_{i=1}^{m}{y_k^{(i)}log(h_\theta(x^{(i)})) + (1-y_k^{(i)})log(1-h_\theta(x^{(i)})) })+\sum_{i=0}^{n}{\theta_i^2}
\end{split}\\
\begin{cases}
\theta^T x >1,  & y=1\\      \theta^T x<-1, & y=0
\end{cases}
\end{gather*}


Since the first line of equation is long, I have to split it to two lines. The problem is that split does not recognise my frame structure ( two columns). I have also tried to use \\ and splits it manually but it does not work (since I have parentheses which separate two to line)
I am using beamer in ubuntu 16 and texlive full 2016. Thanks you in advance and this is the complete frame:

\documentclass{beamer}
\mode<presentation> {
\setbeamertemplate{footline}[page number]
}

\usepackage{graphicx}           % Allows including images
\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables

\begin{document}
\begin{frame}
\frametitle{SVM: Large Margin  classifier}
\begin{columns}
\begin{column}{.64\textwidth}
\begin{block}{Large margin classifier}
For linearly separable case: SVM choose the boundary with largest margin
\begin{gather*}
\begin{split}
J=C(\sum_{i=1}^{m}{y_k^{(i)}log(h_\theta(x^{(i)})) + (1-y_k^{(i)})log(1-h_\theta(x^{(i)})) })+\sum_{i=0}^{n}{\theta_i^2}
\end{split}\\
\begin{cases}
\theta^T x >1,  & y=1\\      \theta^T x<-1, & y=0
\end{cases}
\end{gather*}
\end{block}
\end{column}
\begin{column}{.32\textwidth}
%   \includegraphics[scale=.3]{SVM-large-margin}
\end{column}

\end{columns}
\end{frame}
\end{document}


For split equation, you need to set anchor, where it should be split. For example:

\begin{split}
J & = C\biggl[ \sum_{i=1}^{m} y_k^{(i)}log(h_\theta(x^{(i)})) + \\
&   (1-y_k^{(i)})log(1-h_\theta(x^{(i)})) \biggr]
+ \sum_{i=0}^{n}{\theta_i^2}
\end{split}


(note added ampersand and \\).

However in your case I would use multlined environment from mathtools:

which doesn't need ampersands and broke equation into two line on more (to my opinion) "natural" way.

\documentclass[demo]{beamer}% <-- demo only for test, delete it in real document
\mode<presentation> {
\setbeamertemplate{footline}[page number]
}

\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables

\begin{document}
\begin{frame}
\frametitle{SVM: Large Margin  classifier}
\begin{columns}
\begin{column}{.64\textwidth}
\begin{block}{Large margin classifier}
For linearly separable case: SVM choose the boundary with largest margin
\begin{gather*}
\begin{multlined}[0.9\linewidth]
J   = C\Biggl[ \sum_{i=1}^{m} y_k^{(i)}\log(h_\theta(x^{(i)})) + \\
(1-y_k^{(i)})\log(1-h_\theta(x^{(i)})) \Biggr]
+ \sum_{i=0}^{n}{\theta_i^2}
\end{multlined}\\
\min_\theta J(\theta) \text{ is equal to" }\\
\begin{cases}
\theta^T x >1,  & y=1\\      \theta^T x<-1, & y=0
\end{cases}
\end{gather*}

\end{block}
\end{column}
\begin{column}{.32\textwidth}
\includegraphics[width=\linewidth]{SVM-large-margin}
\end{column}

\end{columns}
\end{frame}
\end{document}


Edit: I strongly encourage you to consider Mico comment below as I do in changes in above MWE. In it I also remove package graphicx from preamble (it is already load with beamer!) and add options demo to beamer, which enable to show your figure. Of course, in real document you should delete this option. For figure size I would rather determine its maximal width than scale it.

• You should probably replace log with \log, and also replace \underset{\theta}{minimize} with \min_{\theta}. – Mico Feb 6 '17 at 11:11
• @Rasoul, here is habits that thankfulness you express with voting for answer :) (klick on upper pen at left top side of answers) or even accept it, if it solve your problem on the best way. – Zarko Feb 6 '17 at 11:12
• @Mico, yes, with this changes the equation will make more sense. I should confess that I was lost in the formulation of equation. I will corect this in the second example. – Zarko Feb 6 '17 at 11:14
• @Rasoul, see changes in edited answer. – Zarko Feb 6 '17 at 11:32
• @zarko . It seems I have long way to go. I have applied all your comments. Thanks. ( by the way I have tried to vote for response but I could not) – Rasoul Feb 6 '17 at 14:11

The split environment doesn't break its contents automatically. It requires you to specify where to split the equation. In the following example I did specify a line break. Also, I've changed the size of two sets of parentheses to make the formula more clear. The reason why the manual split didn't work for you is likely the braces which surrounded the summand. They aren't really necessary.

\documentclass{beamer}
\mode<presentation> {
\setbeamertemplate{footline}[page number]
}

\usepackage{graphicx}           % Allows including images
\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables

\begin{document}
\begin{frame}
\frametitle{SVM: Large Margin  classifier}
\begin{columns}
\begin{column}{.64\textwidth}
\begin{block}{Large margin classifier}
For linearly separable case: SVM choose the boundary with largest margin
\begin{gather*}
\begin{split}
J&=C\biggl(\sum_{i=1}^{m}\Bigl(y_k^{(i)}\log(h_\theta(x^{(i)}))\\
&+ (1-y_k^{(i)})\log(1-h_\theta(x^{(i)}))\Bigr)\biggr)+\sum_{i=0}^{n}{\theta_i^2}
\end{split}\\
\begin{cases}
\theta^T x >1,  & y=1\\      \theta^T x<-1, & y=0
\end{cases}
\end{gather*}
\end{block}
\end{column}
\begin{column}{.32\textwidth}
%   \includegraphics[scale=.3]{SVM-large-margin}
\end{column}

\end{columns}
\end{frame}
\end{document}