%20%E3%81%A8%E3%83%AA%E3%82%B9%E3%83%88%E9%96%93%E3%81%AE%E5%86%85%E9%83%A8%E4%BD%99%E7%99%BD%E3%82%92%E5%A2%97%E3%82%84%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%3F.png)
以下の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}
編集:
「ブラックライン」問題に対する考えられる解決策:
両方の黒い線を削除して「非表示」にするには、
rulecolor
リスト スタイルの設定にキーワードを追加するだけです。rulecolor=\color[RGB]{200,200,200},
実際に上の行を削除して印刷しないようにし、下の行は残しておきます
frame=bt
(これは間隔に必要なため)。ただし、スタイル設定の後のプリアンブルに次のコードを追加して、「上」のフレームのみのルール幅を 0 に設定します。\usepackage{etoolbox} \makeatletter \patchcmd{\lst@frameh}{\color@begingroup}{\color@begingroup\if#2T\let\lst@framerulewidth\z@ \fi}{}{} \makeatother
これら 2 つの解決策のうち、私は個人的には最初の解決策を好みます。下部にある 1 本の黒い線は視覚的にそれほど魅力的ではないと思うからです。