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?

Psychonaut
  • 3,142
Olöf
  • 73
  • 3
    It can't be done automatically, see 17.6 Breakable boxes and the multicol package in the documentation. – Ulrike Fischer Jul 15 '16 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 '16 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 '16 at 23:11
  • \onecolumn or \twocolumn ? This is just standard LaTeX, mind - the default stuff. – cfr Jul 16 '16 at 00: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 '16 at 00:14
  • No. You can't do that. That is why I specified whole pages. You mentioned only wanting to change for pages. My point was that, if that were all, you didn't need multicol. That's all. If that's not all, you do need it (or something, anyway) and you have to break the boxes by hand, if boxes you must have. – cfr Jul 16 '16 at 00:16
  • Do you want to change it for one or more entire pages (e.g. pages 345, 567 and 1,236 only) or do you want to change it for parts of pages? The first doesn't need anything non-standard. The commands I gave above are sufficient. The second isn't supported out-of-the-box, hence multicol. – cfr Jul 16 '16 at 00:19
  • Ok, thank you! Do you know how I could break boxes by hand? Or why doesn't 'breakable' work in the 'multicol's? – Olöf Jul 16 '16 at 00:19
  • I would like to change the column number for parts of the page and need multicol. But also, I would like to have the tcolorboxes broken within when a column ends. – Olöf Jul 16 '16 at 00:20
  • I think you just have to put the stuff in two boxes rather than one. – cfr Jul 16 '16 at 00:22
  • May be these answers can help you: http://tex.stackexchange.com/a/355586/1952, http://tex.stackexchange.com/a/355499/1952 – Ignasi Mar 22 '17 at 20:34

1 Answers1

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}
G. Bay
  • 2,047