I'm using the tips found in here to show a code listing with a caption. Sometimes the caption is put at the end of the page and the listing on the next page. How can I keep them together?
[Tex/LaTex] keep listing’s caption together with listing
listingspage-breaking
Best Answer
listings
provides the means to create a caption using thecaption={[<short/LoL caption>]<long caption>}
key-value interface:For a "captionless" caption, use the
title
key-value. However, these all parse the listing as-is, allowing for page-breaking where needed and causing a possible break in the (top) caption and subsequent listing. Boxing the entire contents avoids this using thefloat
key is encouraged, since a captioned item should be allowed to move and can be adequately referenced: