12

I would like to insert a source code listing into my beamer presentation. I learnt that we cannot use lstlisting directly in the frame environment, so I am using the following trick:

\defverbatim[colored]\makeset{
\begin{lstlisting}[language=C++,basicstyle=\ttfamily,keywordstyle=\color{blue}]
void make_set(int X) {
  parent[X] = X;
}
\end{lstlisting}
}

\begin{frame}
\makeset
\end{frame}

My lstset is:

\lstset{ %
  backgroundcolor=\color{white}, 
  basicstyle=\footnotesize,       
  breakatwhitespace=false,        
  breaklines=true,                 
  captionpos=b,                    
  commentstyle=\color{mygreen},   
  escapeinside={\%*}{*)},        
  extendedchars=true,              
  frame=single,                  
  keywordstyle=\color{blue},       
  language=Prolog,                
  numbers=left,                    
  numbersep=5pt,                   
  numberstyle=\tiny\color{mygray},
  rulecolor=\color{black},        
  showspaces=false,               
  showstringspaces=false,          
  showtabs=false,                  
  stepnumber=2,                    
  stringstyle=\color{mymauve},   
  tabsize=2,                      
  title=\lstname,                  
  morekeywords={not,\},\{,preconditions,effects },            
  deletekeywords={time}            
}

Unfortunatelty the resulting slide has a thick grey line after the code:

enter image description here

Is there any way to remove the line?

4
  • 8
    No. Use the lstlisting environment as-is, but add the [fragile] option to your frame.
    – Werner
    Commented Mar 8, 2014 at 1:34
  • possible duplicate of Can't insert code in my beamer slide
    – Werner
    Commented Mar 8, 2014 at 1:35
  • Unfortunately lstlisting with fragile frame produces the same results. It is not a duplicate, I can insert code into a beamer slide, but it shows some extra grey area.
    – iensen
    Commented Mar 8, 2014 at 1:46
  • 1
    I'm unable to replicate your problem, even with the \lstset. Please provide a complete, minimal working example (MWE).
    – Werner
    Commented Mar 8, 2014 at 1:50

2 Answers 2

8

I have found the problem. The grey area displayed is for the caption of the code. Apparently it is grey because of the beamer style I am using.

So, setting captionpos to n in lstset fixes the problem.

1
  • Consider accepting your answer, so that your question be removed from the "unanswered" pile.
    – jub0bs
    Commented Mar 8, 2014 at 10:20
8

Instead of using this trick, you can just add the option fragile in your frame

\begin{frame}[t,fragile]{\insertsectionhead}
\begin{columns}
    \begin{column}{0.6\textwidth}
    Calcul Symbolique (\textit{calcul formel})
        \begin{itemize}
            \item Algorithme sur les objets mathématiques
        \end{itemize}
        \Rcode
        \begin{lstlisting}
dsolve({diff(y(x),x,x)-3*y(x)=x,y(0)=1,D(y)(0)=2},y(x));
        \end{lstlisting}
    \end{column}
\end{frame}

enter image description here

You must log in to answer this question.

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