# How can I remove the space between listing and text in scrartlc?

I am trying to write one line of code in a listing in scrartlc. The problem is that the space between the listing and the text below is too big.

How it looks when using scrartlc:

This is how it looks like when changing \documentclass[parskip=full]{scrartlc} to \documentclass{article}:

I want to get the same result as I got with article but with scrartlc. How do I get it like this?

Here is my code:

\documentclass[parskip=full]{scrartcl}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\lstdefinestyle{customjava}{
language=Java,
keywordstyle=\bfseries\color{green!40!black},
\lstset{escapechar=@, style=customjava}
}

\begin{document}
test
\begin{lstlisting}
public int a;
\end{lstlisting}
test
\end{document}

• Do you want to remove this space for all lstlistigs or just for a single one? If it's just for a single one maybe \end{lstlisting} \vskip-\belowdisplayskip test could help. – samcarter is at topanswers.xyz Jun 23 '17 at 17:30
• Thank you very much! It works. What could I do for removing the space for all listings? – sininen Jun 23 '17 at 18:06

The additional vertical space comes from the parskip option. You will get a similar issue if you use the standard class article with package \parskip.

If you do not want to remove option parskip=full, then you could use

\usepackage{etoolbox}
\newlength\savedparskip
\BeforeBeginEnvironment{lstlisting}{\setlength\savedparskip{\parskip}}
\lstset{belowskip=\dimexpr-\savedparskip+\medskipamount\relax}


Code:

\documentclass[
parskip=full
]{scrartcl}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\lstdefinestyle{customjava}{
language=Java,
keywordstyle=\bfseries\color{green!40!black}
}
\lstset{escapechar=@, style=customjava}

\usepackage{etoolbox}
\newlength\savedparskip
\BeforeBeginEnvironment{lstlisting}{\setlength\savedparskip{\parskip}}
\lstset{belowskip=\dimexpr-\savedparskip+\medskipamount\relax}

\begin{document}
test
\begin{lstlisting}
public int a;
\end{lstlisting}
test
\end{document}


You could define one or more lstenvironments with custom settings.

\documentclass[parskip=full]{scrartcl}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}

\makeatletter
\lstnewenvironment{rmlisting}
{\lstset{escapechar=@, language=Java,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
keywordstyle=\color{Green},
stringstyle=\color{Purpple}}
}
{
\vspace*{-12pt}
}
\makeatother

\begin{document}

test
\begin{lstlisting}
public int a;
\end{lstlisting}
test

test
\begin{rmlisting}
public int a; @%and here your comment etc@
\end{rmlisting}
test

\end{document}


See here how it works