I'm using listings
to list code in my document, and I want the code to be displayed in a frame with rounded corners and a grey background color. But the background overflows the frame, as if the frame was square.
Here's a minimal example:
\documentclass[a4paper, 11pt]{article}
\usepackage{color}
\usepackage{listings}
\begin{document}
\lstset{basicstyle=\footnotesize\ttfamily, xleftmargin=1em, xrightmargin=1em,
frame=single, framesep=1em, frameround=tttt,
backgroundcolor=\color[rgb]{0.85, 0.85, 0.85}, captionpos=b}
\begin{lstlisting}
bla bla bla
\end{lstlisting}
\end{document}
Result:
Any idea on how to fix this?
EDIT
I got the example working now. The problem was due to old versions of required packages.
Best Answer
Based on the link in my comment I created an environment in which you can use the
lstlistings
-environment:Code
Result
LimitationThis solution works only for non page breaking listings. See the answers to Test if a paragraph has a page break in it? for an idea how this could work.See Update 3Update
I put this three lines to the above example to patch the
lstlisting
environment dircetly. So there’s no need to put it manually in\begin{code} … \end{code}
anymore.Update 2
I created a new command
\lstcapt[<Short>]{<Text>}
to set a caption out of the frame, and added it to the above example code.Update 3
I changed to mdframed instead of using TikZ directly to solve the page breaking problem as Marco suggested.
Update 4
Please note that this code needs
etoolbox
v2.1 or higer …Update 5: Filelist
This is the result of
\filelist
before\documentclass