I have the following settings for a lstlisting:

  numbersep=5pt,                  % how far the line-numbers are from the code
  backgroundcolor=\color{white},      % choose the background color. You must
  showspaces=false,               % show spaces adding
  showstringspaces=false,         % underline spaces
  showtabs=false,                 % show tabs within strings
  frame=single,                   % adds a frame
  rulecolor=\color{black},        % if not set, the frame-color
  tabsize=2,                      % sets default tabsize to 2 spaces
  captionpos=b,                   % sets the caption-position to bottom
  breaklines=true,                % sets automatic line breaking
  breakatwhitespace=false,        % sets if automatic breaks should only happen
  title=\lstname,                   % show the filename of files
                                  % also try caption instead of title
  keywordstyle=\color{blue},          % keyword style
  commentstyle=\color{dkgreen},       % comment style stringstyle=\color{mauve},

The problem occurs when I add a listing in the end of a page. Sometimes it happens that the caption of the listing shows up on the next page - without any code:

new page without code but caption

I do want to have page-breaks in my listings but I don't want to have breaks before the caption.

closed as too localized by lockstep, Marco Daniel, Claudio Fiandrino, Stefan Kottwitz Feb 16 '13 at 12:38

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • needspace package can help you? – kiss my armpit Sep 9 '12 at 16:47
  • how would I use that in order to keep page-breaks, but avoid breaking before the caption? – DIDoS Sep 9 '12 at 16:59