Tell me more ×
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.

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.

share|improve this question
In my previous answer, if you need a border (since the background is already fixed), you just have to change the color colframe=white from the tcolorbox version or linecolor=white in the mdframed version. – Claudio Fiandrino Jan 10 at 8:50
@Werner, Im getting errors with that solution. Im running Article, not memoir perhaps. – ADP Jan 10 at 8:58
@Claudio. tcolor box is the best, but it cant pagebreak.... – ADP Jan 10 at 8:59
@ADP: I agree with you :); my previous comment should be intended as a way to get the border that in the other question was not necessary. Notice, however, that in the solution suggested by Werner, the first example has article as documentclass: only the second goes under memoir. – Claudio Fiandrino Jan 10 at 9:58
show 2 more comments

1 Answer

up vote 10 down vote accepted

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}
share|improve this answer
Nice. So you actually hook into multicols "column output routine"? – Martin Schröder Jan 10 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 at 12:51

Your Answer

 
discard

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.