3

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}
6

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.

|improve this answer|||||
  • 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
4

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> {
  \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\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}\\
                \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}
|improve this answer|||||

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.