I have simple document:
\subsubsection{Dodanie testu}
\begin{lstlisting}[caption={ComplexTest},label={lst:complex-test}]
public class ComplexTest{
public testComplexAddition(){
Complex a = new Complex(1,2);
Complex b = new Complex(3,4);
}
\end{lstlisting}
Some text
\subsubsection{Uruchomienie testów}
Some text
\subsubsection{Napisanie kodu}
Some text
with these settings for my listings:
\lstset{
language=Java,
captionpos=t,
tabsize=3,
frame=none,
keywordstyle=\color{blue},
commentstyle=\color{darkgreen},
stringstyle=\color{red},
numbers=left,
numbersep=-8pt,
showstringspaces=false,
basicstyle={\small\ttfamily}
}
my output looks like
for first page:

for second page:

but when I put \pagebreak just before \begin{lstlisting} to have it on the next page I have got strange vertical spaces between subsubsections and texts. There is the output:

PS. The same occours when I put additional lines of code to my listing and Latex implicit breaks line and put these lines on next page.
\newpageinstead. – Sigur May 01 '14 at 22:58\clearpage? – Sigur May 01 '14 at 23:02