1

I am trying to put a whole \chapter inside of a breakable tcolorbox. This results in the box being broken even before the chapter heading and an almost empty page is added. The following MWE shows this:

\documentclass[a4paper]{book}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcolorbox}[enhanced, breakable]
\chapter*{A chapter}
\lipsum[1-7]
\end{tcolorbox}

\end{document}

Is there a way how to prevent this initial page break?

2

The cause of the early breaking is \clearpage -- a chapter by default uses \cleardoublepage which calls \clearpage, so a new page is shipped, leading to premature breaking of the tcolorbox.

Preventing this:

Using before upper={\let\clearpage\relax} as option leaves the change of \clearpage internally to the tcolorbox and does not leak outside:

\documentclass[a4paper]{book}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\begin{document}
\tableofcontents

\begin{tcolorbox}[enhanced, breakable,before upper={\let\clearpage\relax}]
\chapter*{A chapter}
\lipsum[1-7]
\end{tcolorbox}
% Just for testing
\chapter{Another chapter}

\end{document}

enter image description here

0

You can locally redefine the \clearpage command, that \chapter seems to use, in order to prevent it from doing anything.

\documentclass[a4paper]{book}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\begin{document}

\newcommand*{\mychap}[1]{%
    \begingroup%
        \let\clearpage\relax%
        \chapter*{#1}
    \endgroup%
}

\begin{tcolorbox}[enhanced, breakable]
\mychap{A chapter}
\lipsum[1-7]
\end{tcolorbox}

\end{document}

Screenshot

There might be side effects, though; I'm not sure. Alternatively, redefine \@makeschapterhead (it works for the report documentclass, so maybe for books too). This is a command that typesets the heading for \chapter*. This should be documented in some places.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.