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 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}

sample image for small and large listing space

share|improve this question

1 Answer 1

h floats get \intextsep space above and below the floats.

t floats get \floatsep between each float and \textfloatsep between the last float in the top area and the start of the text area.

You can set these lengths with \setlength

share|improve this answer
    
Is there a way to only change this for the floats of the listings and not for images, tables and further elements? –  martin Aug 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 Carlisle Aug 9 '12 at 13:30

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.