Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following settings for a lstlisting:

    \lstset{
  language=XML,
  numbers=left,        
  numberstyle=\tiny\color{gray},
  stepnumber=1,                   
  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},
  breakautoindent=true,
  framextopmargin=6pt,
  framexbottommargin=6pt,
  belowcaptionskip=10pt,
  abovecaptionskip=1.2em,
  aboveskip=15pt,
}

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.

share|improve this question

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? –  Fifa Earth Cup 2014 Sep 9 '12 at 16:47
    
how would I use that in order to keep page-breaks, but avoid breaking before the caption? –  ele Sep 9 '12 at 16:59
add comment