captionof 摧毁了 parskip

captionof 摧毁了 parskip

我正在使用带有块段落的标题。一旦显示标题,段落之间就没有间隙了。有人能帮忙吗?

\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

也许您可以使用选项captioncaptionpos环境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}

在此处输入图片描述

相关内容