1

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?

4

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.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\makeatletter
\newif\ifaddmarks

\gdef \@makecol {%
   \ifvoid\footins
    \ifaddmarks
     \setbox\@outputbox \vbox{%
       \boxmaxdepth \@maxdepth
       \pgfmark{startof\thepage}%
       \unvbox \@cclv
       \@tempskipa\lastskip \unskip\pgfmark{endof\thepage}\vskip\@tempskipa
      }% 
    \else
     \setbox\@outputbox \box\@cclv
    \fi 
   \else
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \ifaddmarks\pgfmark{startof\thepage}\fi%
       \unvbox \@cclv
       \ifaddmarks\@tempskipa\lastskip \unskip\pgfmark{endof\thepage}\vskip\@tempskipa\fi
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
       }%
   \fi
   \let\@elt\relax
   \xdef\@freelist{\@freelist\@midlist}%
   \global \let \@midlist \@empty
   \@combinefloats
   \ifvbox\@kludgeins
     \@makespecialcolbox
   \else
     \setbox\@outputbox \vbox to\@colht {%
       \@texttop
       \dimen@ \dp\@outputbox
       \unvbox \@outputbox
       \vskip -\dimen@
       \@textbottom
       }%
   \fi
   \global \maxdepth \@maxdepth
}

\usepackage{fancyhdr}
\pagestyle{fancy}
\chead{%
      \ifaddmarks
          \tikz[overlay,remember picture] 
           \draw[red,fill=gray!50!white,opacity=0.5]
            ([xshift=-2pt]pic cs:startof\thepage) 
            rectangle 
            ([xshift=\linewidth+2pt,yshift=-2pt]pic cs:endof\thepage);
      \fi
      }

\begin{document}

\addmarkstrue
abc\newpage

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

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

\newpage
aaaa

\lipsum

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

\lipsum*[1-2]\footnote{\lipsum[1]}

\lipsum*[1-2]\footnote{\lipsum[1]}

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

\end{document}
  • Does this also work without fancyhdr? – kuuhkuuh Jun 12 '16 at 18:23
  • 1
    Yes, you can also add the drawing code e.g. with eso-pic to the pages. fancyhdr was the fasted. – Ulrike Fischer Jun 12 '16 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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