matze / mtheme

A modern LaTeX Beamer theme
6.44k stars 845 forks source link

algorithms do not work on Overleaf version #317

Closed amir-rahnama closed 6 years ago

amir-rahnama commented 6 years ago

Hi,

I am using your theme and I love it, really. It's just that I can't get algorithms to work (I am using the theme in Overleaf).

This is what I code:

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

The frame code:

\begin{frame}[fragile]{Optimization in Machine Learning}
\begin{algorithm}
\caption{Euclid’s algorithm}\label{alg:euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{frame}

and the error says: ./demo.vrb:3: LaTeX Error: Not in outer par mode.

liantze commented 6 years ago

It's not related to the metropolis theme, but rather with beamer: The algorithm floating environment still fails in a vanilla beamer document, without loading any themes. See also https://tex.stackexchange.com/a/26542/226

amir-rahnama commented 6 years ago

@liantze thanks for the response. Is there any way to write algorithms in the beamer?

liantze commented 6 years ago

@ambodi I just updated my comment above with a link; had clicked the button too soon just now!

amir-rahnama commented 6 years ago

Thanks @liantze! it worked

sroder commented 6 years ago

\usepackage[ruled]{algorithm2e} worked for me after inculding [option=ruled]