24

I use the following settings for code listings.

\usepackage{listings}
\usepackage{textcomp}
\lstset{language=Java,
    keywordstyle=\color{RoyalBlue},
    basicstyle=\scriptsize\ttfamily,
    commentstyle=\color{Green}\ttfamily,
    rulecolor=\color{black},
    upquote=true,
    numbers=left,
    numberstyle=\tiny\color{gray},
    stepnumber=1,
    numbersep=8pt,
    showstringspaces=false,
    breaklines=true,
    frameround=ftff,
    frame=single,
    belowcaptionskip=.25\baselineskip
}

I want to add some white space at the bottom of the listing to separate it from the paragraph. How can I adjust the bottom margin below the code listing?

36

Use belowskip (p. 16 and 28 of the listings manual):

Vertical space The keys aboveskip and belowskip control the vertical space above and below displayed listings. Both keys get a dimension or skip as value and are initialized to \medskipamount.

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{textcomp}
\lstset{language=Java,
    keywordstyle=\color{RoyalBlue},
    basicstyle=\scriptsize\ttfamily,
    commentstyle=\color{Green}\ttfamily,
    rulecolor=\color{black},
    upquote=true,
    numbers=left,
    numberstyle=\tiny\color{gray},
    stepnumber=1,
    numbersep=8pt,
    showstringspaces=false,
    breaklines=true,
    frameround=ftff,
    frame=single,
    belowcaptionskip=5em,
    belowskip=3em,
}

\begin{document}

\begin{lstlisting}
// Hello.java
import javax.swing.JApplet;
import java.awt.Graphics;

public class Hello extends JApplet {
    public void paintComponent(final Graphics g) {
        g.drawString("Hello, world!", 65, 95);
    }
}
\end{lstlisting}
This is my text.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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