![captionof 摧毁了 parskip](https://linux22.com/image/353591/captionof%20%E6%91%A7%E6%AF%81%E4%BA%86%20parskip.png)
我正在使用带有块段落的标题。一旦显示标题,段落之间就没有间隙了。有人能帮忙吗?
\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}