1

This question already has an answer here:

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: First page

for second page:

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:

Failure spaces

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.

marked as duplicate by Heiko Oberdiek, Werner, Guido, cmhughes, jub0bs May 2 '14 at 0:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Use \newpage instead. – Sigur May 1 '14 at 22:58
  • It dosen't work. Still the same problem. – klimat May 1 '14 at 23:01
  • What about \clearpage? – Sigur May 1 '14 at 23:02
  • @Sigur it also dosen't work. – klimat May 1 '14 at 23:07
  • Welcome to TeX.SX! – Heiko Oberdiek May 1 '14 at 23:07

Browse other questions tagged or ask your own question.