Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

enter image description here

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.

share|improve this question
    
The skip you see is the skip between caption and content. You can remove it with \captionsetup[lstlisting]{...,skip=0pt}. –  Axel Sommerfeldt Jan 22 '13 at 18:52
    
Awesome, thanks! –  Pragmatick Jan 23 '13 at 11:56
add comment

1 Answer

Switching comment to answer:

The skip you see is the skip between caption and content. You can remove it with \captionsetup[lstlisting]{...,skip=0pt}

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.