# How to make a twocolumn breakable colored environment in book template

I'm trying to create a twocolumn breakable colored environment in tufte book template but using mdframed and tcolorbox wasn't useful.the error is : multicolumn does not make sense in a box!

\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
\setlength{\parindent}{0pt}
%%------------------------------
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum,multicol}

\begin{document}
\begin{tcolorbox}[width=\textwidth,
enhanced,
%%frame hidden,
interior hidden,
boxsep=0pt,
left=0pt,
right=0pt,
top=2pt,
]%%
\twocolumn  \lipsum[1-10]
\end{tcolorbox}
\end{document}


tcolorbox can be used inside a multicols environment and boxes will break accordingly. But a multicol environment can only be used inside non breakable tcolorboxes.

But with magazine and raster libraries help it's possible to do something which looks like a multicol environment inside a breakable tcolorbox.

magazine library provides tools to store fragments of broken tcolorboxes inside an array. Later on these fragments can be inserted in our text as needed, even in different order. (See magazine origin: tcolorbox: Can one store the parts of a breakable tcolorbox for later use?)

Once we have all fragments, we can use a tcboxedraster or tcboxeditemize to compose all fragment like a boxed multicolumn.

This process is not automatic, first we should decide how large are initial fragments, and we have to know how many fragments has been produced because we have to manually type each one inside the raster. Not easy but possible.

A little example:

Some text: \lipsum[1-8] is broken in .93\textheight X .42\textwidth fragments and they are stored into a default array of blanker boxes:

\begin{tcolorbox}[blanker,
width=.42\textwidth,
breakable,
break at=.93\textheight,
%break at=.93\textheight/.93\textheight/.4\textheight,
reset box array,
store to box array,]
\lipsum[1-8]
\end{tcolorbox}


This text is only processed and stored, it's not printed at all.

Later on these fragments (3 in this case, although \boxarraygetsize{\mysize} will store the fragments number in \mysize) can be printed inside a raster or a tcboxeditemize like in this case.

\begin{tcboxeditemize}[%
blanker,
raster columns=2,
sharp corners,
halign=center,
raster valign=top]{%
breakable,
colback=yellow!20,
fonttitle=\bfseries\large,
colframe=red!80!yellow,
title=Breakable twocolumn tcolorbox,
title after break= Second and last part,
}
\tcbitem\consumeboxarray{1}
\tcbitem\consumeboxarray{2}
\tcbitem\consumeboxarray{3}
\tcbitem\consumeboxarray{4}
\end{tcboxeditemize}


\consumeboxarray{1} uses and deletes the first fragment. As we have only three fragments, the reference to the fourth one is ignored without disturbing the work.

The result looks like:

If you prefer to better balance the second page, it's possible to do it but we have to manually set all fragments length. As an example:

break at=.93\textheight/.93\textheight/.4\textheight,


will force two breaks after .93\textheight lengths and all other ones will have .4\textheight length. With this numbers the result is:

And this is the complete code:

\documentclass[a4paper,12pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{multicol}
\usepackage{lipsum}

\begin{document}
\begin{tcolorbox}[blanker,
width=.42\textwidth,
breakable,
break at=.93\textheight,
%break at=.93\textheight/.93\textheight/.4\textheight,
reset box array,
store to box array,]
\lipsum[1-8]
\end{tcolorbox}

\begin{tcboxeditemize}[%
blanker,
raster columns=2,
sharp corners,
halign=center,
raster valign=top]{%
breakable,
colback=yellow!20,
fonttitle=\bfseries\large,
colframe=red!80!yellow,
title=Breakable twocolumn tcolorbox,
title after break= Second and last part,
}
\tcbitem\consumeboxarray{1}
\tcbitem\consumeboxarray{2}
\tcbitem\consumeboxarray{3}
\tcbitem\consumeboxarray{4}
\end{tcboxeditemize}

\end{document}


\twocolumn inside a box doesn't make sense. But outside it works fine with tcolorbox. You can also use multicols inside a tcolorbox but only if this is not breakable. If you want a frame around both columns of two column document you should draw it with other means, e.g. as background image with eso-pic.

\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
\setlength{\parindent}{0pt}
%%------------------------------
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{multicol,lipsum}

\begin{document}
\twocolumn
\begin{tcolorbox}[width=\linewidth, %\linewidth, not \textwidth!
enhanced,
breakable
]%%
\lipsum[1-10]
\end{tcolorbox}

\onecolumn
\begin{tcolorbox}[width=\textwidth,
enhanced,
colback=blue!20!white
%breakable %won't work
]%%
\begin{multicols}{2}
\lipsum[1-2]
\end{multicols}
\end{tcolorbox}

\end{document}

• Thanks for your approach but your codes make tcolorbox twocolumned,while I'm looking for a twocolumned text in fullwidth tcolorbox. – Mrt Nov 21 '16 at 11:10
• Well the second example (with the blue background) shows a twocolumn text in a fullwidth tcolorbox. – Ulrike Fischer Nov 21 '16 at 11:12
• Thank you again for your kind response but according to your codes,breakable won't work here, while a breakable environment is needed. – Mrt Nov 21 '16 at 11:38