2

I am using listings package in Beamer. If I use inline listing, there is no problem and the listings look good. However, if I use \begin{lstlisting}, it is required to use fragile frame and the listings become urly. Too much space between characters.

Attached are the minimal running example and the output that describe my problem.

Much appreciated if you can help me to fix this.

\documentclass{beamer}
\usetheme{Montpellier}
\usecolortheme{crane}

\usepackage{listings}
\lstset{
  language=HTML,
  basicstyle={\small\ttfamily},
  breaklines=true
}

\begin{document}


\begin{frame}[fragile]
\frametitle{Question -- Beamer-Listings-Fragile}

Inline listing, good looking: 
\lstinline!<link rel="stylesheet" type="text/css" href="filename"/>!

\vspace{4ex}
Too much space for this:
\begin{lstlisting}
<link rel="stylesheet" type="text/css" href="filename"/>
\end{lstlisting}

\end{frame}

\end{document}

enter image description here

5

The options aboveskip and belowskip control the spacing around lstlisting environments. By default they are medskip but you can set them to zero. If doing this with a \lstset command in beamer this needs to be after \begin{document}. The additional letter spacing in the environment is standard behaviour of listings; set columns=flexible to change this (see the package documentation for other variations):

Sample output

\documentclass{beamer}
\usetheme{Montpellier}
\usecolortheme{crane}

\usepackage{listings}
\lstset{
  language=HTML,
  basicstyle={\small\ttfamily},
  breaklines=true,
  columns=flexible
}

\begin{document}
\lstset{aboveskip=0pt, belowskip=0pt}

\begin{frame}[fragile]
\frametitle{Question -- Beamer-Listings-Fragile}

Inline listing, good looking: 
\lstinline!<link rel="stylesheet" type="text/css" href="filename"/>!

\vspace{4ex}
Was too much space for this:
\begin{lstlisting}
<link rel="stylesheet" type="text/css" href="filename"/>
\end{lstlisting}

\end{frame}

\end{document}

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.