7

When using a tcolorbox with the breakable option, this may cause a "ragged bottom" in some special situations. The following MWE demonstrates this behaviour:

\documentclass[DIV=10, BCOR=10mm, twoside]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{lipsum}

\usepackage{tcolorbox}
\tcbuselibrary{theorems, skins, breakable}
\newtcbtheorem[auto counter]{mytheo}{My Theorem}{
  enhanced, breakable, colback=white, colbacktitle=black!15, coltitle=black, fonttitle=\bfseries,
  before skip=15pt plus 4pt minus 2pt,
  after skip =15pt plus 4pt minus 2pt
}{th}

\begin{document}

\lipsum[1-5]

\begin{mytheo}{This is my title}{theoexample}
\lipsum[6]
\end{mytheo}

\lipsum[6-10]

\end{document}

ragged bottom

As you can see from the screenshot, the bottom of the first page is not aligned. Nevertheless, LaTeX does not print out any underfull vbox warnings. It looks as if some part of the invisible before skip has been located on the bottom of page 1, even though the actual tcolorbox itself is completely on page 2.

If you remove the breakable option, this does not change the appearance of the box (since the box has not been broken anyway), but LaTeX warns about the underfull vbox as you would expect.

Is there any possibility to solve this problem without relinquishing breakable boxes?

3
  • Surely the problem is not with the breakable boxes, but rather the fact that the box will not break immediately after the title -- where would you want it to break? Feb 10, 2016 at 15:20
  • @Aubrey In this specific case, it would obviously not be very sensible to break the box right after the title. I'm not even sure if there would be enough space for the title part to be placed on the bottom of page 1.
    – ph4nt0m
    Feb 10, 2016 at 15:45
  • You would get the same imbalance if you simply replaced the colorbox by \clearpage (which is effectively what you are doing by placing a tcolorbox that cannot fit or break). I think. Feb 10, 2016 at 19:41

1 Answer 1

4

The following answer is valid for tcolorbox prior to version 3.90 (2016/02/29). Starting from that version, the before skip option should not leave tracks when a page break occurs.

tcolorbox has to insert certain code (including the before skip) before the remaining height can be calculated. Here, the inserted skip apperently is not removed automatically.

I can offer the following 'hotfix' which inserts a negative skip at the \pagebreak. Currently, I have not the time to investigate possible negative impacts of this patch further, but for before skip the following seems to work:

\documentclass[DIV=10, BCOR=10mm, twoside]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{lipsum}


\usepackage{tcolorbox}
\tcbuselibrary{theorems, skins, breakable}

%--- begin patch ---
\makeatletter

\def\tcb@undo@before{}

\tcbset{
  before skip/.style={before={%
    \ifnum\lastnodetype=-1\relax%
    \else%
      \par\ifvmode\nointerlineskip%
      \addvspace{\glueexpr#1-\parskip}%
      \def\tcb@undo@before{\addvspace{-\glueexpr#1}}%
      \fi%
    \fi%
    \lineskip=0pt\noindent%
    }},
}

\def\tcb@split@start{%
  \tcb@breakat@init%
  \tcb@comp@h@page%
  % height calculation
  \tcb@comp@h@total@standalone%
  %
  \let\tcb@split@next=\relax%
  \tcb@check@for@final@box%
  \iftcb@final@box%
    \tcb@drawcolorbox@standalone%
  \else%
    \iftcb@break@allowed%
      \ifdim\dimexpr\tcb@h@page-\tcb@h@padding-\tcb@h@padtitle<\kvtcb@breakminlines\baselineskip\relax%
        \tcb@undo@before\iftcb@multicol\columnbreak\else\pagebreak\fi%            
        \tcb@nobreak@warning%
        \tcb@enlbreak@init\tcb@break@allowedfalse%
        \tcb@comp@h@page%
        \tcb@check@for@final@box%
        \iftcb@final@box%
          \tcb@drawcolorbox@standalone%
        \else%
          \let\tcb@split@next=\tcb@split@first%
        \fi%
      \else%
        \let\tcb@split@next=\tcb@split@first%
      \fi%
    \else%
      \let\tcb@split@next=\tcb@split@first%
    \fi%
  \fi%
  \tcb@split@next%
}

\makeatother
%--- end patch ---

\newtcbtheorem[auto counter]{mytheo}{My Theorem}{
  enhanced,
  breakable,
  colback=white, colbacktitle=black!15, coltitle=black, fonttitle=\bfseries,
  before skip=15pt plus 4pt minus 2pt,
  %before=,
  after skip =15pt plus 4pt minus 2pt
}{th}

\begin{document}

\lipsum[1-5]

\begin{mytheo}{This is my title}{theoexample}
\lipsum[6]
\end{mytheo}

\lipsum[6-10]

\end{document}
2
  • a not relevant comment, but why all those %'s after the last control sequences on each line ? except if you want to protect agains a non-standard \endlinechar, there is no need for them.
    – user4686
    Feb 11, 2016 at 10:51
  • 1
    @jfbu Well, it's a habit of mine to add a % automatically in every macro line, because a not needed one does not hurt, but a forgotten one does. Feb 11, 2016 at 11:38

You must log in to answer this question.

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