TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When using a combination of the packages framed, listings, and xcolor, that causes a strange bug, that I cannot manage to fix.

The problem is that, when a box (made with the framed package, and fcolorbox) contains a listing just before a page breaks, the rest of the block appears blank on the next page. Moreover, the block on the firxt page is not framed anymore.

enter image description here

This does not happens if I use fbox instead of fcolorbox.

The minimal example is the following:










def f(x):
End of block

What I am looking for is any kind of workaround, not necessarily a full solution.

share|improve this question
up vote 2 down vote accepted

Adding \color{black} after \end{python} solves the problem (but a color stack warning appears). It seems that somehow the "white" background becomes also the text color after the python environment.


Use mdframed. A simple


produces what you are looking for. The environment is customizable in many ways.

share|improve this answer
Haha, brilliant! This is indeed what is happening: the text after the page break becomes the background colour! Thanks! – Olivier Jul 21 '11 at 14:04
There is still the issue of the framing, though. The frame on the first page disappears... – Olivier Jul 21 '11 at 14:06
Sorry. It has to do with the inner workings of framed that gathers its contents and all the catcode tricks of listings cannot be performed properly. I believe that mdframed can do a better job. – egreg Jul 21 '11 at 14:20
Thanks, this is brilliant. Exactly the right solution. This package mdframed seems much more reliable than framed. I also prefer the result. – Olivier Jul 21 '11 at 17:05

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.