35

My MWE is

\documentclass[pdf]{beamer}
\usepackage[lined]{algorithm2e}

\begin{document}

\begin{frame}
\begin{algorithm}
\DontPrintSemicolon
\KwIn{Labels: set of all labels}
\KwIn{F: combinatorial logic function} 
\KwIn{Lat: lattice representation of all labels}
\KwIn{X: set of inputs to F with values in 0,1}
\KwOut{$Sh_F$: truth table for shadow F}
\For{each XRow $\in$ XSet}{
\For{each LRow $\in$ LSet}{
CandidateSet $\gets$ $\phi$\;
\For{each $label \in Labels$} {
$C \gets \phi$\;
\For{each $l_i \in LRow$} {
\If{\underline{Lat.conflictsWith}($l_i$,label)}{
$C \gets C \cup \{x_i\}$ \;
}
}
\If{!\underline{isAffectedBy}(F,$X_{row}$,C)}{
CandidateSet $\gets$ CandidateSet $\cap$ \{label\} \;
}
}
$SHF_{row} \gets$ Lat.ChooseMin(CandidateSet) \;
Output $X_{row}$, $T_{row}$, $SHF_{row}$ \;
}
}
\end{algorithm}
\end{frame}

\end{document}

this results in following error

! LaTeX Error: Not in outer par mode.
0

1 Answer 1

65

Floating environments can cause problems in beamer, so you need to force the algorithm to stay in place with a [H] specification:

\documentclass[pdf]{beamer}
\usepackage[lined]{algorithm2e}

\begin{document}
\begin{frame}
\scalebox{.7}{                        %new code
    \begin{algorithm}[H]              %new code
        \DontPrintSemicolon
        \KwIn{Labels: set of all labels}
        \KwIn{F: combinatorial logic function}
        \KwIn{Lat: lattice representation of all labels}
        \KwIn{X: set of inputs to F with values in 0,1}
        \KwOut{$Sh_F$: truth table for shadow F}
        \For{each XRow $\in$ XSet}{
        \For{each LRow $\in$ LSet}{
        CandidateSet $\gets$ $\phi$\;
        \For{each $label \in Labels$} {
        $C \gets \phi$\;
        \For{each $l_i \in LRow$} {
        \If{\underline{Lat.conflictsWith}($l_i$,label)}{
        $C \gets C \cup \{x_i\}$ \;
        }
        }
        \If{!\underline{isAffectedBy}(F,$X_{row}$,C)}{
        CandidateSet $\gets$ CandidateSet $\cap$ \{label\} \;
        }
        }
        $SHF_{row} \gets$ Lat.ChooseMin(CandidateSet) \;
        Output $X_{row}$, $T_{row}$, $SHF_{row}$ \;
        }
        }
    \end{algorithm}
}
\end{frame}
\end{document}

I've also scaled down a bit with \scalebox, since it didn't fit the frame.

enter image description here

4
  • 2
    What does the [H] specifier do?
    – gsamaras
    Mar 1, 2017 at 17:24
  • 3
    @gsamaras forces the algorithm environment to stay in place and not float. The algorithm env works like the figure env, it floats by default. In beamer floating makes no sense, so you need to force the env to stay where the code is.
    – d-cmst
    Mar 1, 2017 at 18:15
  • 5
    Why do we need this for algorithm environment but not for figures? Oct 11, 2019 at 10:13
  • @CyriacAntony, presumably beamer has special code for this (very important) special case.
    – vonbrand
    Sep 11, 2020 at 0:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .