I have several pages of text in my book that i want to put in a box with a lightgrey background. I was trying to use mdframed, and lookswise it is what i wished for. However, I use (several) footnotes over the several pages and they all turn up at the end of the box, either as a footnote or in the box, depending on my settings. As far as I know, mdframed does not know how to continue the footnote count and put the footnotes on the respective page, so I wonder: Is there a good alternative to mdframed to created box with a differently colored background, that supports footnotes fully?


1 Answer 1


Neither mdframed nor tcolorbox (which I would always prefer over mdframed) can handle "global" footnotes in combination with breakable boxes. You could try something like the following to draw your background manually, but be aware that is fiddles with the output routine. This means

  • it can clash with packages which fiddle with the output too
  • it can break
  • it can have side effects on spacing of the page
  • it can break
  • it can break
  • You should carefully decide when to enable the marks (with \addmarkstrue) and when to disable them (with \addmarksfalse).

I didn't try to add special drawing for the first or the last page, but it should be difficult to start the rectangle in the middle of the page. I also didn't check twocolumn mode or special output modes.


\gdef \@makecol {%
     \setbox\@outputbox \vbox{%
       \boxmaxdepth \@maxdepth
       \unvbox \@cclv
       \@tempskipa\lastskip \unskip\pgfmark{endof\thepage}\vskip\@tempskipa
     \setbox\@outputbox \box\@cclv
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \unvbox \@cclv
       \ifaddmarks\@tempskipa\lastskip \unskip\pgfmark{endof\thepage}\vskip\@tempskipa\fi
       \vskip \skip\footins
         \unvbox \footins
   \global \let \@midlist \@empty
     \setbox\@outputbox \vbox to\@colht {%
       \dimen@ \dp\@outputbox
       \unvbox \@outputbox
       \vskip -\dimen@
   \global \maxdepth \@maxdepth

          \tikz[overlay,remember picture] 
            ([xshift=-2pt]pic cs:startof\thepage) 
            ([xshift=\linewidth+2pt,yshift=-2pt]pic cs:endof\thepage);



blblbl \begin{figure}[t!] a figure\end{figure}

blblbl \begin{figure}[h!] a figure\end{figure}



\lipsum*[1-2] bböööbö\footnote{\lipsum[1]}



\newpage\addmarksfalse %needed to avoid a gray empty page because of the splitted footnote

  • Does this also work without fancyhdr?
    – kuuhkuuh
    Commented Jun 12, 2016 at 18:23
  • 1
    Yes, you can also add the drawing code e.g. with eso-pic to the pages. fancyhdr was the fasted. Commented Jun 12, 2016 at 18:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .