リスト: キャプション (上部) とリスト間の内部余白を増やしますか?

リスト: キャプション (上部) とリスト間の内部余白を増やしますか?

以下のMWE(ここ)、次のように表示されるのではなく、リストの内部余白を増やすにはどうすればよいですか。

ここに画像の説明を入力してください

次のようになります (灰色の背景が少し「引き伸ばされている」ことに注意してください)。

ここに画像の説明を入力してください

framextopmarginなどをいじってみましたbelowcaptionskipが、うまくいかないようです内部マージン。

\documentclass{article}
\usepackage[svgnames]{xcolor} 
\usepackage{caption}
\usepackage{listings}
\usepackage{calc} 
\lstdefinestyle{outline}{
         basicstyle=\scriptsize\ttfamily,
         numberstyle=\tiny,
         numbersep=5pt,
         tabsize=2,
         extendedchars=true,
         breaklines=true,
         keywordstyle=\color{blue},
         frame=b,
         stringstyle=\color{green!40!black}\ttfamily,
         showspaces=false,
         showtabs=false,
         numbers=left,
         xleftmargin=17pt,
         framexleftmargin=17pt,
         showstringspaces=false,
         backgroundcolor=\color[RGB]{200,200,200},
         belowcaptionskip=-1pt
}

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[RGB]{60,100,180}{\parbox{\textwidth - 2 \fboxsep}{\hspace{14pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}

\begin{document}
\begin{lstlisting}[style=outline,caption=Test]
First line.
Second line.
\end{lstlisting}
\end{document}

答え1

framextopmargin効果を出すには、上部にフレーム ラインが必要なようです。キャプションとフレーム自体の間に細い黒い線があることを除けば、これはまさにあなたが求めていたものです。

\documentclass{article}
\usepackage[svgnames]{xcolor} 
\usepackage{caption}
\usepackage{listings}
\usepackage{calc} 
\lstdefinestyle{outline}{
         basicstyle=\scriptsize\ttfamily,
         numberstyle=\tiny,
         numbersep=5pt,
         tabsize=2,
         extendedchars=true,
         breaklines=true,
         keywordstyle=\color{blue},
         frame=bt,  % <<<<<<<<<<<<<<<<<<<<<<<<<<
         stringstyle=\color{green!40!black}\ttfamily,
         showspaces=false,
         showtabs=false,
         numbers=left,
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framextopmargin=1pt, % <<<<<<<<<<<<<<<<<<<<<<
         showstringspaces=false,
         backgroundcolor=\color[RGB]{200,200,200},
         belowcaptionskip=0pt
}

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[RGB]{60,100,180}{\parbox{\textwidth - 2 \fboxsep}{\hspace{14pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}

\begin{document}
\begin{lstlisting}[style=outline,caption=Test]
First line.
Second line.
\end{lstlisting}
\end{document}

フレーム

編集:

「ブラックライン」問題に対する考えられる解決策:

  1. 両方の黒い線を削除して「非表示」にするには、rulecolorリスト スタイルの設定にキーワードを追加するだけです。

    rulecolor=\color[RGB]{200,200,200},
    
  2. 実際に上の行を削除して印刷しないようにし、下の行は残しておきますframe=bt(これは間隔に必要なため)。ただし、スタイル設定の後のプリアンブルに次のコードを追加して、「上」のフレームのみのルール幅を 0 に設定します。

    \usepackage{etoolbox}
    \makeatletter
    \patchcmd{\lst@frameh}{\color@begingroup}{\color@begingroup\if#2T\let\lst@framerulewidth\z@ \fi}{}{}
    \makeatother
    

これら 2 つの解決策のうち、私は個人的には最初の解決策を好みます。下部にある 1 本の黒い線は視覚的にそれほど魅力的ではないと思うからです。

関連情報