[Tex/LaTex] Create manual page break within tcolorbox

tcolorbox

I am wanting to insert a new page within a tcolorbox environment but the following example shows it ignores the \newpage command:

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage[breakable,skins]{tcolorbox}

\newtcolorbox{activitybox}{%
    breakable,
    enhanced,
    colback=white,
    colframe=black,
    coltitle=white,
    title={\bfseries Title}
}

\begin{document}

\begin{activitybox}
    \lipsum[1]
    \newpage
    \lipsum[1]
\end{activitybox}

\end{document}

The documentation suggests the only way to do this is create a fake break (page 373) where I create two separate tcolorbox environments between the \newpage command with the skin parameters set to skin=enhancedfirst and skin=enhancedlast respectively.

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage[breakable,skins]{tcolorbox}

\newtcolorbox{activitybox}[1][]{%
    breakable,
    enhanced,
    colback=white,
    colframe=black,
    coltitle=white,
    #1
}

\begin{document}

\begin{activitybox}[title=Title,skin=enhancedfirst]
    \lipsum[1]
\end{activitybox}
\newpage
\begin{activitybox}[skin=enhancedlast]
    \lipsum[1]
\end{activitybox}

\end{document}

The trouble with this idea is the new page might need to get placed within environments. These will then have to be closed prematurely and opened again while making sure the environment state is continued from before. There may also be further beginning and ending definitions within those environments that shouldn't be called since the environment has not truly ended and is still continuing over the page.

An alternative solution is to make use of the break at (page 355) parameter which will break the tcolorbox at a given length. This is unusable in my situation since the number of tcolorbox environments goes into the hundreds with each edit of the document needing a recalculation of each break at parameter which in turn is only possible after a full render of the document to be able to measure the new length by hand.

At a lower level a page break is possible when breakable (page 351) is enabled and the tcolourbox environment needs to span more than one page. Is it possible to fire that page break at a higher level or at least fill in the rest of the page with blank vertical space?

Best Answer

You could use

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage[breakable,skins]{tcolorbox}

\newtcolorbox{activitybox}[1][]{%
    breakable,
    enhanced,
    colback=white,
    colframe=black,
    coltitle=white,
    #1
}
\newcommand*{\fakebreak}{\par\vspace{\textheight minus \textheight}\pagebreak}


\begin{document}

\begin{activitybox}[title=Title]
    \lipsum[1]

    \fakebreak

    \lipsum[1]
\end{activitybox}

\end{document}

But note, that the result is different, because the box will be filled to the page end!

If you want similar behaviour for automatic breaks, use option height fixed for=first and middle:

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage[breakable,skins]{tcolorbox}

\newtcolorbox{activitybox}[1][]{%
    breakable,
    enhanced,
    colback=white,
    colframe=black,
    coltitle=white,
    #1
}
\newcommand*{\fakebreak}{\par\vspace{\textheight minus \textheight}\pagebreak}


\begin{document}

\begin{activitybox}[title=Title,height fixed for=first and middle]
    \lipsum[1]

    \fakebreak

    \lipsum[1-2]
    \parbox{\linewidth}{\lipsum[3-4]}% \parbox used to force an early page break
    \lipsum[5-7]
\end{activitybox}

\end{document}
Related Question