2

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?

  • I don't think this will work with \newpage -- A tcolorbox content is read into a box register and the total height of the box (i.e. height and depth) is measured -- if this is too large for the page, the box is broken (if breakable has been enabled). However, \newpage does not really add extra spacing such that the box would get too high, so \newpage can't trigger a break – user31729 Jan 25 '17 at 6:18
  • Do you think it is possible to fire that same page break at a higher level or at least fill the rest of the page with blank vertical space so one is triggered? – A Dark Divided Gem Jan 25 '17 at 6:32
3

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}
  • Thanks, I assume there isn't a parameter that ensures the border is displayed right to the page end when a breakable box is continued over the page? Just to ensure a consistency in style. – A Dark Divided Gem Jan 25 '17 at 7:38
  • @ADarkDividedGem See height fixed for=first and middle in the manual. – Schweinebacke Jan 25 '17 at 8:20

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.