I want to add a caption and label on a Minted source code so I can reference it, similarly to what you can do to figures.
In Minted manual it says I can use the listing environment, which allows to use both caption and label, the problem is that listings creates a float and only allows to use one page. My source code is long and spans on two pages.
How can I add caption and label but still be able to use two pages?
Best Answer
You can define a non-floating environment which can break over pages and put the
minted
environment in that one. This is a documented feature:Loading
minted.sty
withnewfloat
option enables you to customize thelisting
environment,caption.sty
offers\captionof
for captions outside floating environments. Check their docs for further (plenty of) options.Putting it together: