3

The following compiles under cleveref v0.19 and tcolorbox v3.80 with TeXLive 2013 under osx 10.6.8 but the left box is cut short.

% !TEX TS-program = pdflatexmk  

\documentclass{book}

\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins, raster} 

\newtcolorbox[auto counter,
number within=chapter]{EXAMPLE}[1][]{% 
breakable,
enhanced,
grow to left by=5mm,
grow to right by=5mm,
detach title,
before upper={\tcbtitle\quad},
fontupper=\small\sffamily,
colframe=white,
colback=white,
coltitle=black,
title={EXAM},
#1}

\begin{document}

\chapter{One}
Some text to show the margins. Some text to show the margins. Some text to show the margins.  

\begin{tcbraster}[raster columns=2, raster valign=top]
\begin{EXAMPLE}[unbreakable]{Some Title}
tcolorbox requires for a box to be rasterized that it be unbreakable. 
\end{EXAMPLE}
\begin{EXAMPLE}[unbreakable]{Some Title}
This is my own box.
\end{EXAMPLE}
\end{tcbraster}

\end{document}
2
  • I cannot check right now, but cleveref is not used here
    – user31729
    Mar 6, 2016 at 18:47
  • Correct. I normally do have cleveref for cref and cpageref. Took it out of the code but not of the message. Sigh.
    – schremmer
    Mar 7, 2016 at 4:08

1 Answer 1

4

You have a problem with grow to left by and grow to right by. These options change bounding box compared with needed box and boxes overlaps when placed with a raster.

Next figure shows how both boxes are placed with a raster but declared without grow to option:

enter image description here

Now with your original design:

enter image description here

Dotted red line is obtained with show bounding box option, while the red line is tcolorbox frame. As you can see, bounding boxes are correctly placed but because tcolorboxes are not transparent (colback=white) and used boxes are larger than their bounds, right box covers part of left one.

A possible solution would be to use empty skin, which draws nothing around or inside the box and makes its contents transparent. Another solution could change inner box margins without enlarging it. The first option produces

enter image description here

with following code:

\documentclass{book}

\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins, raster} 

\newtcolorbox[auto counter,
number within=chapter]{EXAMPLE}[1][]{% 
breakable,
enhanced,
empty,
grow to left by=5mm,
grow to right by=5mm,
detach title,
before upper={\tcbtitle\quad},
fontupper=\small\sffamily,
colframe=red,
colback=white,
coltitle=black,
%show bounding box,
title={EXAM},
#1}

\begin{document}

\chapter{One}
Some text to show the margins. Some text to show the margins. Some text to show the margins.  

\begin{tcbraster}[raster columns=2, raster valign=top]
\begin{EXAMPLE}[unbreakable]{Some Title}
tcolorbox requires for a box to be rasterized that it be unbreakable. 
\end{EXAMPLE}
\begin{EXAMPLE}[unbreakable]{Some Title}
This is my own box.
\end{EXAMPLE}
\end{tcbraster}

\end{document}

Update:

For boxes being as much wide as possible, it's better to use size=minimal (page 43) which builds boxes without padding or rules. EXAMPLE box could be declared like:

 \newtcolorbox[auto counter,
number within=chapter]{EXAMPLE}[1][]{% 
breakable,
enhanced,
size=minimal,
detach title,
before upper={\tcbtitle\quad},
fontupper=\small\sffamily,
colframe=red,
colback=white,
coltitle=black,
show bounding box,
title={EXAM},
#1}

enter image description here

4
  • Without grow ... the overlap is indeed gone but I need the text in the two boxes to be as wide as possible. So, how do I reduce the left and right margins inside the boxes? (But the show bounding box is very useful.)
    – schremmer
    Mar 6, 2016 at 20:36
  • As a hack, left=-1mm,right=-1mm, seems to do it.
    – schremmer
    Mar 6, 2016 at 21:17
  • 2
    @schremmer: Updated answer with size=minimal option. I think it's better than tweaking with margins.
    – Ignasi
    Mar 7, 2016 at 8:03
  • I knew mine was only a hack. It worked but this is just right. Thanks. So, now all is welll and I can return to ... writing,
    – schremmer
    Mar 8, 2016 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .