0

I currently have breakable tcolorboxes and floating tables in proximity in my document. In some instances, the tcolorbox will break and the table will (default) float to the top of the page and in the middle of the tcolorbox.

Is there a way to give precedence to the broken tcolorboxes over floating objects so that the broken boxes are not interrupted by other objects? I'm reluctant to set after=\clearpage because I don't want a hanging blank page after the tcolorbox before content resumes.

MWE with pdflatex via TeXLive 2019:

\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
  \tcbuselibrary{breakable}
  \tcbuselibrary{skins}

\begin{document}

\begin{tcolorbox}[enhanced, breakable,title=My breakable box] \lipsum[1-6] \end{tcolorbox}

\begin{table} \caption{My Table}

\centering{}% \begin{tabular}{ccc} a & b & c \ 1 & 2 & 3 \ \end{tabular} \end{table}

\end{document}

Result: enter image description here

  • If you use [ht] it will never go to the top of the first page. See also https://tex.stackexchange.com/questions/425892/place-figure-at-bottom-of-this-page-or-the-top-of-the-next-page?r=SearchResults&s=1|79.2181 – John Kormylo Mar 30 '21 at 14:39
  • @JohnKormylo True, but I don't want to try to control my tables (and tcolorboxes) on a case-by-case basis. This is for a large document with many such boxes and tables. – Joel Kulesza Mar 30 '21 at 14:41

1 Answers1

3

You can prevent a top float being on that page with \suppressfloats[t]

\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
  \tcbuselibrary{breakable}
  \tcbuselibrary{skins}

\begin{document}

\begin{tcolorbox}[enhanced, breakable,title=My breakable box] \lipsum[1-6] \end{tcolorbox} \suppressfloats[t]

\begin{table} \caption{My Table}

\centering \begin{tabular}{ccc} a & b & c \ 1 & 2 & 3 \ \end{tabular} \end{table}

\end{document}

David Carlisle
  • 757,742
  • Thanks. I hadn't known about \suppressfloats. Two clarifications: (1) can this be used to put the float after the tcolorbox rather than at the bottom of the page and (2) is there a downside to putting \begin{tcolorbox}[..., after={\suppressfloats[t]}] or via tcbset? – Joel Kulesza Mar 30 '21 at 14:39
  • The default is [tbp] (no [h]). However you could append \supressFloat[t] to \endtcolorbox. – John Kormylo Mar 30 '21 at 14:55
  • as @JohnKormylo says you would need to allow h so use [htp] or similar on the float. as well as stopping t. – David Carlisle Mar 30 '21 at 16:32