#StackBounty: #spacing #tcolorbox #multicol Tight packing of tcolorboxes in multicols environment

Bounty: 100

For a formulary, I want to put several (ideally breakable) tcolorboxes in a multicols environment. The following code is a very basic example of what I already did:

documentclass[landscape, parskip=half]{scrartcl}

usepackage[hmargin=1cm, vmargin=1cm]{geometry}
usepackage{showframe}

usepackage{tcolorbox}
tcbuselibrary{breakable}
tcbuselibrary{skins}
tcbset{
    breakable, % << comment for a different weird behaviour
    % lines before break=5, % << the warning message suggests to increase this value
    frame empty,
    blank,
    left=3mm, right=3mm,
    borderline vertical={1pt}{0pt}{black},
    colbacktitle={black!20},
    coltitle=black,
}

newtcolorbox[use counter*=subsection]{block}[1][]{before title={thetcbcounter:~},#1}

% for testing
usepackage{blindtext}
NewDocumentCommand{testbox}{m}{
    foreach i in {0,...,#1}{
        begin{block}[title=This is a test-box]
            par
            framebox(linewidth,1cm){foo}
            
            framebox(linewidth,2cm){foo}
            
            framebox(linewidth,1.3cm){foo}
        end{block}
    }
}

usepackage{multicol}

title{Box-Packing}
begin{document}
begin{multicols*}{4}
maketitle

section{Foo}
testbox{4}

section{Bar}
testbox{3}

section{Baz}
testbox{2}

end{multicols*}
end{document}

Unfortunately, I get some weird balancing of the columns (mostly direct after a section)
Weird balancing

Following the suggestion in the warning, and increasing lines before break gives the following:
With lines before break increased

Just for the record: disabling breakable wouldn’t work either:
no breakable

Are there any ways to improve the packing of the tcolorboxes in a multicols environment (ideally breakable)?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.