6

I would like to have my tcolorboxes with breakable inside my multicols environment. But they do not break. Also:

\documentclass[a4paper, twocolumn]{article}

Would not work for me, because for some sections I need the whole page and for some sections, I would like multiple columns.

My header is:

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage[svgnames]{xcolor}                           % colour extension
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}              % Todo notes
\usepackage[sfdefault,thin]{roboto}                     % Roboto font
\usepackage{fullpage}
\usepackage{longtable}                                  
\usepackage{tcolorbox}                                  % Colored boxes
\usepackage{xparse}                     % For squeezing of section titles
\tcbuselibrary{skins,breakable}              % breakable for tcolorboxes

My tcolorbox is:

\newenvironment{tada}
{\begin{tcolorbox}[colback=Green!14!white,
colframe=Green!10!blue!29!white,
sharp corners, breakable]}{\end{tcolorbox}} 

And I call it like:

\begin{multicols}{2}

\begin{tada}
** Here should be written the lipsum text **
\end{tada}

\end{multicols}

Now, if that is at the end of a page, the long lipsum text would not be broken by splitting of the tcolorbox as it should be by the command breakable above.

Someone have a clue how to solve this?

11
  • 3
    It can't be done automatically, see 17.6 Breakable boxes and the multicol package in the documentation. Jul 15, 2016 at 16:25
  • You can switch whole pages between one and two columns using the standard class option and standard commands. You don't need multicol for that.
    – cfr
    Jul 15, 2016 at 21:05
  • @cfr Can you give an example how two switch number of columns inside the document with the standard class option?
    – Olöf
    Jul 15, 2016 at 23:11
  • \onecolumn or \twocolumn ? This is just standard LaTeX, mind - the default stuff.
    – cfr
    Jul 16, 2016 at 0:13
  • @cfr What I mean is, break the page in one tiny section within the page into two columns only. While having the document in onecolumn overall. I only know `\documentclass[a4paper, twocolumn]{article}, but then the whole document is in twocolumn. So could you give an example of how you mean it?
    – Olöf
    Jul 16, 2016 at 0:14

1 Answer 1

3

I had the same issue with a document of mine and what fixed the problem for me was this answer from egreg, so I included the code here too.

\RenewDocumentEnvironment{multicols}{mO{}}
 {%
  \ifnum#1=1
    #2%
  \else % More than 1 column
    \multicolmulticols{#1}[#2]
  \fi
 }
 {%
  \ifnum#1=1
  \else % More than 1 column
    \endmulticolmulticols
  \fi
 }

I hope this is what you were looking for (full MWE below).

tcolorbox multicolumn breakable

\documentclass[a4paper,]{article}
\usepackage{lipsum} %to use lipsum
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage[svgnames]{xcolor}                           
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}              
\usepackage[sfdefault,thin]{roboto}                     
\usepackage{fullpage}
\usepackage{longtable}                                  
\usepackage[many]{tcolorbox}                                  
\usepackage{xparse}                    
\tcbuselibrary{skins,breakable}              
\newenvironment{tada}
{\begin{tcolorbox}[enhanced jigsaw, colback=Green!14!white,
colframe=Green!10!blue!29!white,
sharp corners, breakable]}{\end{tcolorbox}} 
%
\let\multicolmulticols\multicols
\let\endmulticolmulticols\endmulticols

\RenewDocumentEnvironment{multicols}{mO{}}
 {%
  \ifnum#1=1
    #2%
  \else % More than 1 column
    \multicolmulticols{#1}[#2]
  \fi
 }
 {%
  \ifnum#1=1
  \else % More than 1 column
    \endmulticolmulticols
  \fi
 }
%

\begin{document}
\begin{multicols}{1}
\begin{tada}
\lipsum[1]
\end{tada}
\lipsum[1]
\end{multicols}
\begin{multicols}{2}
\lipsum[1]
\begin{tada}
\lipsum[2-4]
\end{tada}
\lipsum[5]
\end{multicols}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .