ブロック段落でキャプションを使用しています。キャプションが表示されると段落間に隙間がなくなります。どなたか助けていただけませんか?
\documentclass[a4paper,10pt]{article}
\usepackage{parskip}
\usepackage{lipsum}
\usepackage[skip=-5pt, font=scriptsize]{caption}
\usepackage{listings}
\usepackage{color}
\usepackage{float}
\newfloat{Snippet}{th}{snippets}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=Python,
basicstyle={\scriptsize\ttfamily},
numbers=none,
numberstyle=\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
tabsize=4
}
\begin{document}
\begin{lstlisting}
primary_colours = ["red", "blue", "yellow"]
\end{lstlisting}
\lipsum[2]
\lipsum[2]
\begin{lstlisting}
primary_colours = ["red", "blue", "yellow"]
\end{lstlisting}
\captionof{Snippet}{\texttt{primary\_colours}}
\lipsum[2]
\lipsum[2]
\end{document}
答え1
おそらく、オプションcaption
と環境captionpos
を使用できますlstlisting
。
\documentclass[a4paper,10pt]{article}
\usepackage{parskip}
\usepackage{lipsum}
\usepackage[skip=-5pt, font=scriptsize]{caption}
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=Python,
basicstyle={\scriptsize\ttfamily},
numbers=none,
numberstyle=\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
tabsize=4
}
\renewcommand\lstlistingname{Snippet}
\begin{document}
\begin{lstlisting}
primary_colours = ["red", "blue", "yellow"]
\end{lstlisting}
\lipsum[2]
\lipsum[2]
\begin{lstlisting}[caption={\texttt{primary\_colours}},captionpos=b]
primary_colours = ["red", "blue", "yellow"]
\end{lstlisting}
\lipsum[2]
\lipsum[2]
\end{document}