[Tex/LaTex] How to split an equation inside two columns frame of beamer

beamerequationssplittwo-column

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}\\
        \text{for }C\gg 1 \qquad \underset{\theta}{minimize}\quad J(\theta) \text{ is equal to" }\\
        \underset{\theta}{minimize}\quad\sum_{i=0}^{n}{\theta_i^2}\\  
        \qquad \qquad \qquad \qquad \text{s.t.  }
        \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> {
  \usetheme{Madrid}
  \setbeamertemplate{footline}[page number]
}

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

\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}\\
                \text{for }C\gg 1 \qquad \underset{\theta}{minimize}\quad J(\theta) \text{ is equal to" }\\
                \underset{\theta}{minimize}\quad\sum_{i=0}^{n}{\theta_i^2}\\  
                \qquad \qquad \qquad \qquad \text{s.t.  }
                \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}

Best Answer

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 \\).

enter image description here

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

enter image description here

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> {
  \usetheme{Madrid}
  \setbeamertemplate{footline}[page number]
}

\usepackage{booktabs}           % Allows the use of \toprule,
                                % \midrule and \bottomrule in tables
\usepackage{tikz}               % add background image
\usepackage{mathtools}               % add background image

\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}\\
                \text{for }C\gg 1 \qquad 
                        \min_\theta J(\theta) \text{ is equal to" }\\
                \quad   \min_\theta \sum_{i=0}^{n}{\theta_i^2}\\
                \qquad \qquad \qquad \qquad \text{s.t.  }
                \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.

Related Question