1

I have a problem with the paragraph spacing in my \documentclass{article}. I am using \lstset{} function (Code Listings), LOF and TOF. I want to have a 1em spacing between my paragraph text and the Listings space above and below should have the same space like with my figures. I know that \usepackage{parskip} adds spaces but every where there is a "new line (picture or text)" there is added space. Is there a way where I can set the space in my premable? or other ways?

\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}
2
  • Why don't you just use \vspace{1em} before the listing?
    – Johannes_B
    Aug 19, 2018 at 5:24
  • is also an option, however then it is a little inconsistent...
    – Alan
    Aug 21, 2018 at 20:29

1 Answer 1

1

As I understand the listings manual (you get it with texdoc listingson the command line), one might have aboveskip= and belowskip=, so I added both to your setup with a value of, as you asked, 1cm.

To have the same skip as other floats, the first thing ist to make listings a float as well. So I added float=hto the setup.

And that's it:

\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}

Looks good with your example!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .