I know you asked for a non-wrapfig
answer, though it is unclear why. They can work together. More importantly, I think, is that tcolorbox
doesn't care much about how things outside the "colorboxes" look or behave, while wrapfig
only cares about wrapping things around other things....
\documentclass{book}
\usepackage[most]{tcolorbox}
\usepackage{lipsum, wrapfig}
% change "top" vertical spacing in wrapfig
\setlength{\intextsep}{0pt}
\begin{document}
\chapter{First}
\section{Furst}
\subsection{Ok}
%Defining a newtcolorbox to be a standard box for all examples in the text:
\newtcolorbox[auto counter,number
within=section]{phbox}[1][]{skin=bicolor,
title=Figure~\thetcbcounter,#1,
size=title,colback=white,colbacklower=black!10!white}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
\begin{wrapfigure}[14]{r}[0pt]{5cm}
\begin{phbox}[label={fig:label},width=\linewidth]
\tcbincludepdf[scale=1,size=tight,opacityframe=0]{example-image.pdf}
\tcblower
Here is a bunch of text to explain a figure.
\end{phbox}
\end{wrapfigure}
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere
\end{document}
Update: For tcolorbox
version 4.03
or higher, this feature is / will be
implemented as option segmentation at break=false
.
First, the behaviour is not a bug. If a break occurs at the segmentation between upper and lower part, then the segmentation line and the lower part go to the next page. There, the segmentation is displayed to signal that the lower part starts.
For bicolor
, the color change also signals the begin of the lower part. So, it may be preferable to have no explicit segmentation line here. I take it as a feature request that the segmentation is optionally not drawn on page breaks :-)
For 'faked' segmentations with \tcbline
, there already is the option to use \tcbline*
instead to get this feature.
For 'real' segmentations, this option is currently not available. But, I think we can do it with the following new option:
\tcbset{
experimental split/.code={\let\tcb@split@SL=\tcb@split@L},
}
With it, the segmentation line is not drawn at the begin of the splitted box. I have to investigate, if this causes some unwanted side-effects. Also, a good name for the feature has to be found (suggestions are welcome).
The full example code is:
\documentclass[11pt]{scrbook}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\makeatletter
\tcbset{
experimental split/.code={\let\tcb@split@SL=\tcb@split@L},
}
\makeatother
\newtcolorbox{example}{breakable,
experimental split,
bicolor,
colback=red!10!white,
colbacklower=blue!5!white,
title={Example}}
\begin{document}
\begin{example}
\lipsum[3-7]
\tcblower
\lipsum[8]
\end{example}
\end{document}
Best Answer
Your code does not work because as soon as you insert
{
, the grouping is initiated, and you would get something likeTo solve this, one can define an environment-version of
\uline
. Here I use the+b
type argument to record the content of the environment and apply\uline
on it.Then you can do
which gives you:
Unfortunately, this approach does not work with
\tcblower
(which pretty much makes theupper
specifier useless). The grouping mechanism here is rather complicated. I'm looking forward if someone can resolve this issue.ADD: If you can guarantee that there shall always be a
\tcblower
in your environment, please then refer to Pieter van Oostrum's nice answer.