# Shaded multicols II

In extending a previous question, Shaded multicols, how can I put rounded corners on the multicol environment, for the outer 4 corners (ie the corners directly next to the page margins)

This question is only really relevant when multicol shading is used, or multicol borders are used, a solution contained in part I of this question (see above link).

So main thing is that the environment needs to be able to page break mid way through. David Carlisle has suggested in one of the comments to patch the box command, but how can this be done to only round the left 2 corners for a left column, the right 2 corners for a right column and, no corners in a middle column (when there are 3 or more columns).

-

As noted in the question, this essentially just replaces \fcolorbox with mdframed (with thanks to Marco for supplying the right mdframed incantation)

\documentclass{article}
\usepackage{multicol}
\usepackage[framemethod=tikz]{mdframed}

\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{%
\ifnum#1=\mult@rightbox
\def\zz{\begin{mdframed}[middlelinewidth=2pt,roundcorner=5pt,leftline=false,backgroundcolor=yellow]}%
\fi
\ifnum#1=\numexpr\mult@rightbox+2\relax
\def\zz{\begin{mdframed}[middlelinewidth=2pt,roundcorner=5pt,rightline=false,backgroundcolor=yellow]}%
\fi
\ifnum#1=\numexpr\mult@rightbox+4\relax
\def\zz{\begin{mdframed}[middlelinewidth=2pt,roundcorner=5pt,rightline=false,leftline=false,backgroundcolor=yellow]}%
\fi
\kern\dimexpr-15pt\relax
{\let\box\old@box\vtop{%
\zz{%
\hbox{\box#1\llap{\phantom p}}}%
\end{mdframed}}}%
\kern\dimexpr-15pt\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}

-
Thanks a million, but how is it exactly determining if the column is left, right or middle? Presumably it will work for 'n' columns? – Nicholas Hamilton May 30 '13 at 22:17
@ADP as written it works for any n so long as n=3. \ifnum#1=\mult@rightbox is the right box \ifnum#1=\numexpr\mult@rightbox+4\relax should be + 2*(n-1) for the left box and the middle one should be the else clause for the other cases. – David Carlisle May 30 '13 at 22:29
He he he. any n as long as n = 3...., funny. – Nicholas Hamilton May 30 '13 at 22:34
@DavidCarlisle When I use your code in twoside mode I have problems with the margins: tex.stackexchange.com/questions/136434/… Do you have any idea what's going wrong? – susis strolch Oct 10 '13 at 12:46
@susisstrolch note that the code here is tuned for 3 columns and you have 2 so you'll need to make adjustments. None of the mdframed margin options are relevant as it is not using mdframed breakable frames it is just using mdframed as a convenient fancy alternative to \fbox to frame a box within the page (as constructed by multicol) – David Carlisle Oct 10 '13 at 13:16