I have a document similar to this:
\documentclass[twoside,11pt,titlepage,a4paper]{report} %unterscheidung zwischen gerade und ungerade seite, 11pkt, kp, kp
\usepackage[T1]{fontenc} %inputcodierung
\usepackage[latin1]{inputenc} %inputcodierung
\usepackage[ngerman]{babel} %deutscher sprachschatz, alte rechtschreibung und vor allem -trennung
\usepackage[babel,german=guillemets]{csquotes} %deutsch mit >><<-anführungszeichen
\usepackage{listings} \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt} %einfache listings
\usepackage{caption} %bildunterschriften
\usepackage{beramono} %schriftart für code
\usepackage{color}
\usepackage{xcolor}
%code-listings
\definecolor{javared}{rgb}{0.6,0,0} % for strings
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
\definecolor{mygrey}{HTML}{575757}
\lstloadlanguages{
[Sharp]C
}
\lstset{
language=[Sharp]C,
basicstyle=\footnotesize\ttfamily, % Standardschrift
numberstyle=\tiny, % Stil der Zeilennummern
numbersep=9pt, % Abstand der Nummern zum Text
tabsize=2, % Groesse von Tabs
extendedchars=true, %
breaklines=true, % Zeilen werden Umgebrochen
frame=lrb,
keywordstyle=\color{javapurple}\bfseries,
stringstyle=\color{javared},
commentstyle=\color{javagreen},
rulecolor=\color{mygrey},
showspaces=false, % Leerzeichen anzeigen ?
showtabs=false, % Tabs anzeigen ?
xleftmargin=25pt,
framexleftmargin=21.5pt,
framexrightmargin=-4pt,
framexbottommargin=3pt,
framextopmargin=3pt,
%backgroundcolor=\color{lightgray},
showstringspaces=false % Leerzeichen in Strings anzeigen ?
}
%----------captions
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}
{\colorbox{mygrey}
{\parbox{0.985\textwidth}{\hspace{14pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
\begin{document}
\begin{lstlisting}[caption=My caption]
Lorem
ipsum
\end{lstlisting}
\end{document}
The resulting PDF looks like this:

You'll notice the strange margin values; I experimented with them until I got (mostly) the result I wanted (caption and bottom line aligning with the text margins left and right). Until recently I only had a b-frame, but now I want a lbr-frame. As you can see, the left and right frame don't get up to the caption but there's a little space left. Any idea how to change that? I got the full document settings here so you can see all the packages I use, if that is any help.
Any advice would be greatly appreciated. If you can get the listing and caption to look like above without all the weird margin settings, even better, but I'd be happy enough if the left and right lines would go up to the box.
\captionsetup[lstlisting]{...,skip=0pt}. – Axel Sommerfeldt Jan 22 at 18:52