I've come across a situation where a breakable tcolorbox is getting covered up by text that follows. I think the vertical stretchable space is lining up just right so that the page breaking and box breaking algorithms get confused. I realize that I could put a \clearpage after the box, but that requires that I notice that this has happened in a fairly long document (and if the box moves, then the \clearpage would be incorrect).
The following document:
\documentclass[10pt]{article}
\usepackage[textheight=7in,textwidth=320pt]{geometry}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\newcommand{\onelineoftext}{this is just about one line of text after I make it long enough for my purposes}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\begin{tcolorbox}[size=minimal,breakable]
One\\Two\\Three
% the page breaks here
\begin{enumerate}
\item one
\item two
\item three
\item four
\end{enumerate}
Text
\begin{enumerate}
\item \onelineoftext\onelineoftext\onelineoftext
\onelineoftext\onelineoftext\onelineoftext\onelineoftext
\onelineoftext\onelineoftext\onelineoftext\onelineoftext
\item One\\two
\item Displayed equation
\[\lim_{x\to0}\cos\cos\cos\cos\cos\frac00\]
\item \onelineoftext\onelineoftext\onelineoftext\onelineoftext
\[\lim_x e^x\]
One
\item One\\two
\[\frac00\]
This text will be overwritten by the next paragraph and completely covered.
I don't understand why.
It seems to involve lots of vertical spacing that's just right,
so I can't eliminate much else.
\end{enumerate}
\end{tcolorbox}
%\clearpage % solves this page, but not the underlying problem
\onelineoftext\onelineoftext\onelineoftext\onelineoftext
\end{document}
has the following at the bottom of the second page (with no bad boxes)
How can I prevent this overlap from happening, or at least have TeX warn me that something went wrong?
Update
From @muzimuzhiZ: Below is a reduced example showing this problem might be caused by too much shrinkable space in tcolorbox
. Text after tcolorbox
is in blue, in order to emphasis the overlapping.
\documentclass{article}
\usepackage[breakable]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\begin{tcolorbox}[size=minimal,breakable]
\begin{enumerate}
\item
\lipsum[1-3]
\vskip 60pt plus 0pt minus 100pt
\lipsum[1-2]
\end{enumerate}
\end{tcolorbox}
\color{blue}\lipsum[1]
\end{document}
\clearpage
here and there, but these command here are not imperfect solutions but the problem. Just remove the first and the second.lipsum
package. Simpler and better.cos
causes the output to adjust and there to be less severe overlap.tcolorbox
.longtable
package, which constructs a long and breakable tabular, encounters similar problem, and a workaround/solution forlongtable
given by David Carlisle can be seen here.