I am using listings from the listings-package.
I'm having a problem with spaces below the listings. I use both, float- with h and non-float listings. The problem now is, that the spaces below the listings that are defined with float are larger than the spaces without the float definition (see MWE).

I want to reduce the space below the floated listing. I already have tested to set belowcaptionskip=-10pt, but then the space of the non floated listing is also reduced.

How do I reduce the space below the floated listing without changing the space below the non-floated listing?

\documentclass[a4paper,12pt]{scrreprt}
\usepackage{listings}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\lstset{captionpos=b,
breaklines=true,
breakatwhitespace=true,
xleftmargin=20pt,
belowcaptionskip=0pt,
basicstyle=\ttfamily\small
}
\begin{document}
\begin{lstlisting}[caption={space below is smaller}]
The space below is smaller
\end{lstlisting}
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
\begin{lstlisting}[float=h, caption={space below is larger}]
The space below is larger
\end{lstlisting}
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
Some text, that appears below the listing.
\end{document}

Is there a way to only change this for the floats of the listings and not for images, tables and further elements?
–
martinAug 9 '12 at 12:27

there's always a way but probably not without defining large chunks of latex. Latex format \@addtocurcol does \vskip \intextsep \box\@currbox \penalty\interlinepenalty \vskip\intextsep to add an h float to the page you would probably need to modify that to add different skips depending on \count\@currbox which will be 1 2 4 8 ... depending on the float type. But this is deep inside the latex output routine: handle with care
–
David CarlisleAug 9 '12 at 13:30