\documentclass{article} 中带有图片和列表的段落间距

\documentclass{article} 中带有图片和列表的段落间距

我的段落间距有问题\documentclass{文章}。 我在用\lstset{}函数(代码清单),劳伦斯到F。我希望段落文本与上方和下方的列表空间之间有 1em 的间距,并且应该与我的图表有相同的间距。我知道\usepackage{parskip}添加空格,但凡有“新行(图片或文本)”的地方都会添加空格。有没有办法在 premable 中设置空格?或者其他方法?

\documentclass[12pt,a4paper,oneside]{article}
\usepackage[top=25mm,bottom=20mm,left=35mm,right=30mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx} % für Grafiken
\usepackage{amsmath}
\usepackage{titlesec}
\usepackage{amssymb}
\usepackage{caption} %Überschriften für Bilder
\captionsetup{font={small,it}}
\usepackage{listings}
\usepackage{color}
\usepackage{times}
\usepackage[numbers,square]{natbib}
\usepackage{blindtext}
\usepackage{fancyhdr}
\usepackage{tabto}
\usepackage{paracol}
\usepackage{tocloft}
\usepackage[onehalfspacing]{setspace}
\usepackage{nomencl}
\usepackage{tabularx}
\usepackage{float} %Position erzwingen
\usepackage{array} %feste Spaltenbreite einstellbar
\usepackage{eurosym}
\usepackage{subcaption}
\usepackage{acronym}


\begin{document}
\begin{titlepage}
    \centering
    \Huge
    Titlepage
\end{titlepage}

\setlength{\parindent}{0em} %keine Einrückung nach Absatz



\section{Mainbody}
This is the text in first paragraph. This is the text in first paragraph. This is the text in first paragraph.

This is the text in second paragraph. This is the text in second paragraph. This is the text in second  paragraph. 

\begin{figure}[H] %please put a picture here for compilation
    \centering
    \includegraphics[width=0.5\textwidth]{Picture.png}
    \caption{Picture}
    \label{picture}
\end{figure}

This is the text in first paragraph. This is the text in first paragraph. This is the text in first paragraph.

This is the text in second paragraph. This is the text in second paragraph. This is the text in second paragraph. 

\lstset{language=PYTHON,label=List:python dummy,frame=single,captionpos=b}
\begin{lstlisting}[caption=Python Dummy]
import socket
\end{lstlisting}

This is the text in first paragraph. This is the text in first paragraph. This is the text in first paragraph.

This is the text in second paragraph. This is the text in second paragraph. This is the text in second paragraph. 

\clearpage


\end{document}

答案1

据我了解,列表手册(您可以texdoc listings在命令行上获得它)可能有aboveskip=belowskip=,所以我将两者都添加到您的设置中,并且正如您所要求的,值为 1cm。

要与其他浮点数一样跳过,首先要将列表也设为浮点数。所以我将其添加float=h到设置中。

就是这样:

\lstset{language=PYTHON,label=List:python dummy,frame=single,captionpos=b,
  aboveskip=1cm, belowskip=1cm, float=h}
\begin{lstlisting}[caption=Python Dummy]
import socket
\end{lstlisting}

您的例子看起来不错!

相关内容