# Getting a frame with listings in beamer

According to my experiments the listings package no longer allows

\begin{frame}[fragile]
\begin{lstlisting}
%CODE HERE
\end{lstlisting}
\end{frame}


you can use

\begin{lstlisting}[frame = single]


to get a line around your frame and you can use title to get a title, but this does not produce the same effect as the regular frames.

Sample code:

\documentclass{beamer} {
\mode<presentation> {
\usetheme{Berkeley}
% or ...

%\setbeamercovered{transparent}
% or whatever (possibly just delete it)
\usecolortheme{albatross}
\usecolortheme{sidebartab}
}

\usepackage{natbib}
\usepackage[english]{babel}
% or whatever

\usepackage[latin1]{inputenc}
% or whatever

\usepackage{array}

\usepackage{booktabs}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}

\usepackage{alltt}
\usepackage{times}

\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.

\usepackage{listings}
\usepackage{multicol}
\usepackage{url}
\lstset{language = SAS}

\setbeamercolor{navigation symbols}{fg = white, bg = white}
\setbeamercolor{sectionintoc}{fg = white}

\title[] % (optional, use only with long paper titles)
{Lies, damn lies and ... SAS to the rescue!}

\author{Peter L. Flom}
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[Peter Flom Consulting] % (optional, but mostly needed)
{Peter Flom Consulting}

\date[Short Occasion] % (optional)
{SESUG \\September, 2015}

\subject{Talks}
% This is only inserted into the PDF information catalog. Can be left
% out.

\AtBeginSubsection[] {
\begin{frame}<beamer>
\frametitle{Outline}
\tableofcontents[currentsubsection]
\end{frame}
}

% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:

%\beamerdefaultoverlayspecification{<+->}

\begin{document}
\lstset{language = SAS}

\section{Introduction}

\begin{lstlisting}[frame = single, title={SAS code for means}]
data means1;
input x @@;
datalines;
210 291 921 922 102
;
run;

proc means data = means1;
var x;
run;
\end{lstlisting}
\end{document}


Is there a way to get "normal" looking frames with listings or should I use one of the verbatim packages?

EDIT June 3, 2015, 7PM Eastern

Per the comments, I tried a simpler version and still got the same error: "Runaway argument? File ended while scanning use of \next"

\documentclass{beamer}

\usepackage{listings}
\lstset{language = SAS}

\title[] % (optional, use only with long paper titles)
{Lies, damn lies and ... SAS to the rescue!}

\author{Peter L. Flom}
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[Peter Flom Consulting] % (optional, but mostly needed)
{Peter Flom Consulting}

\date[Short Occasion] % (optional)
{SESUG \\September, 2015}

\begin{document}
\lstset{language = SAS}

\section{Introduction}

\begin{frame}[fragile]

\begin{lstlisting}[frame = single, title={SAS code for means}]
data means1;
input x @@;
datalines;
210 291 921 922 102
;
run;

proc means data = means1;
var x;
run;
\end{lstlisting}
\end{frame}
\end{document}

• Using fragile should work fine. What's the error when you try to use it? – alaferg Jun 3 '15 at 19:57
• I get the error about "file ended while scanning use of next", if I just add \begin{frame}[fragile] and \end{frame} to my posted code. – Peter Flom - Reinstate Monica Jun 3 '15 at 20:10
• Just ran your MWE, with the addition of \begin{frame}[fragile] and \end{frame}. It compiled fine and I got the one expected slide for your specifice Beamer Theme. So ... go to the folder and delete all generated files except the *.tex file. Add the two commands and compile with pdflatex. – R. Schumacher Jun 3 '15 at 20:41
• This is very odd.. I just did that and got the same error. (I saved the file to a new folder and ran it). – Peter Flom - Reinstate Monica Jun 3 '15 at 20:53
• Try a smaller MWE with just beamer and listings. Do you still get the error? How are you compiling? – alaferg Jun 3 '15 at 22:19

If you remove the spaces before \end{frame} it compiles.
The problem of not being able to indent \end{frame} in fragile frames was fixed in beamer v3.37.