10

Does anyone know how to shade the background and put a border around a multicol environment, where page breaks are needed.

There is a couple of posts around, most notably, multicols within colorbox, but there seems to be problems.

The best looking environment is the tcolorbox, but, cant do pagebreaks.

mdframed appears to overflow when pagebreaks are required (ie when multicol env. across multiple pages)

I really don't have an MWE, given the above comments RE tcolorbox and mdframed.

1 Answers1

13

You might want to play with the spacing a bit but something like this

enter image description here

\documentclass{article}
\usepackage{multicol,color}

\makeatletter
\let\old@page@sofar\page@sofar
\let\old@box\box
\let\old@rlap\rlap
\def\page@sofar{%
\let\box\colorcolumn
\def\rlap{\let\box\old@box\old@rlap}%
\old@page@sofar
}
\def\colorcolumn#1{%
       \kern\dimexpr-\fboxrule-\fboxsep\relax
        {\let\box\old@box\fcolorbox{red}{yellow}{\box#1\llap{\phantom p}}}%
        \kern\dimexpr-\fboxrule-\fboxsep\relax
}

\makeatother


\def\a{Red blue green yellow black white. }
\def\b{One two three four five six. }
\def\c{\stepcounter{enumi} \Roman{enumi}
\a\a\b\b\a\a\b\a\a\b\b\b\b\b\b\a\a\b}
\begin{document}

\begin{multicols}{3}
\c\c\c\c\c\c\c\c\c\c
\end{multicols}

\end{document}
David Carlisle
  • 757,742
  • Nice. So you actually hook into multicols "column output routine"? – Martin Schröder Jan 10 '13 at 12:25
  • 1
    yes @page@sofar is Frank's macro that lines up the boxes with the column text and inserts inter-column rules, This just patches it to add some colour at the same time. – David Carlisle Jan 10 '13 at 12:51
  • @DavidCarlisle How could I put rounded corners on the outside corners on this? – Nicholas Hamilton May 25 '13 at 02:15
  • \fcolorbox{red}{yellow}{....} is the standard (my) macro for butting colour behind a box, you can replace that by anything else that does the same but with more fancy features, tikz or tcolorbox or whatever. – David Carlisle May 25 '13 at 09:43
  • @DavidCarlisle If I want to apply this formatting to a duplicate environment (ie via \let\mymulticol\multicol and \let\myendmulticol\endmulticol), whilst retaining an unmodified version of the original, how is this possible, ie, how to distinguish the page@sofar, \box and \rlap commands between the duplicate and original environments. – Nicholas Hamilton Jun 05 '13 at 21:07
  • @ADP change \def\page@sofar{% in the above to \def\my@page@sofar{% then by default the definition won't be used at all, but in the definition of your custom environment add \let\page@sofar\my@pagesoofar (in a package or after \makeatletter) then locally within your environment the new definition will be in effect and you will get shading. – David Carlisle Jun 05 '13 at 21:14