调整列表环境的底部边距

调整列表环境的底部边距

我使用以下设置来列出代码。

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

我想在列表底部添加一些空白,以将其与段落分开。如何调整代码列表下方的底部边距?

答案1

使用belowskip(第 16 页和第 28 页)listings 手动的):

垂直空间aboveskipbelowskip控制所显示列表上方和下方的垂直空间。两个键均获取维度或跳过作为值,并初始化为\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}

在此处输入图片描述

相关内容