I was using the listings
package to place source code in my document and I noticed that the space between the text and the lstlisting
environment was to little. So I changed the \aboveskip
and \belowskip
properties.
The problem with that was that along with the space I mentioned it was also affected the space between a section header and a lstlisting
environment which is useless and annoying. Also it does not produce a nice document appearance.
Also I don't know if there is the same behaviour in the space between the environment and page breaks or the beginnings of a new page (is it?) or LaTeX erase that space by itself (if it is actually inserted there too).
My question is how can I prevent the space inserted with \aboveskip
and \belowskip
affect the space between section headers, page breaks and beginning of pages?
This is without the \aboveskip
:
This is with \aboveskip=1.5cm
(an excessive number to show the "unnecessary" space under the section title):
\documentclass[12pt]{article}
\usepackage{parskip}
\setlength{\parindent}{0cm}
\usepackage{fontspec}
\usepackage[english,greek]{babel}
\usepackage[fleqn]{amsmath}
\usepackage{unicode-math}
\usepackage{listings}
\setmainfont
[
Ligatures=TeX,
Extension=.otf,
UprightFont=*,
BoldFont=*Bold,
ItalicFont=*It,
BoldItalicFont=*BoldIt,
Mapping=tex-text
]{GFSArtemisia}
\setsansfont[Mapping=tex-text]{GFSArtemisia.otf}
\setmathfont{latinmodern-math.otf}
\setmathfont[range=\varnothing]{Asana-Math.otf}
\setmathfont[range=\int]{latinmodern-math.otf}
\begin{document}
\lstset
{
aboveskip=1.5cm,
frame=tb,
rulecolor=\color{black},
basicstyle=\ttfamily\color{BrickRed},
columns=flexible,
morecomment=[s][\color{NavyBlue}]{/*}{*/}
}
\section*{Section Title}
\begin{lstlisting}
Source code here.
\end{lstlisting}
Text here!
\begin{lstlisting}
More source code here.
\end{lstlisting}
More text here!
\end{document}