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 am trying using minted to display some code in my document, but the code is long and spans over two pages, this works fine, however when I place my code inside

  \caption{Some caption}

Then my code doesn't show up and I get the warning:

LaTeX Warning: Float too large for page

I have tried using the option H in listing, but then the code shows in only one page and it doesn't fit so I only see a part of it.

I also tried with the code directly in the latex document ie:

    Java code
  \caption{Some caption}

But the same happens, any ideas?

share|improve this question

2 Answers 2

up vote 15 down vote accepted

As far as I know, this is a fundamental restriction of floats. You cannot use floats that span over more than one page so you need to remove the surrounding listing.

To make the caption still work, you can load the caption package and use the \captionof command instead of \caption:

\captionof{listing}{Some caption}

Now the caption should also appear in the \listoflistings. If you want to use a label here, you need to put it inside the \captionof command:

\captionof{listing}{Some caption\label{lst:some-label}}

See also: Question “Label and caption without float”.

share|improve this answer
Thanks! This works. Is there a way to also add a label so I can reference it from other part of my text? Also, if I use this, then then \listoflistings won't list my code right? –  lander16 Mar 1 '11 at 20:05
@lander See updated answer. –  Konrad Rudolph Mar 1 '11 at 20:16
Thanks. Everything is working now. –  lander16 Mar 1 '11 at 20:17
\captionof requires an environment so this does not work correctly, see my answer. –  schlamar Apr 27 '12 at 8:43
@ms4py Is right. –  Konrad Rudolph Apr 27 '12 at 8:51

The suggested and accepted answer does not work correctly as the \captionof command requires to be inside an environment. This is pointed out in the caption documentation. For example in my case there was no proper vertical space after the caption.

A proper solution is to define a new environment:


def my_func(x):
    print x
\caption{My Func}
share|improve this answer
When I use this solution with \inputminted, page spanning breaks. –  Stephen Bosch Sep 22 '13 at 14:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.