以下内容在 osx 10.6.8 下的 cleveref v0.19 和 tcolorbox v3.80 与 TeXLive 2013 下进行编译,但左侧框被缩短了。
% !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}
答案1
grow to left by
您对和有疑问grow to right by
。与 相比,这些选项会发生变化,bounding box
当与 一起放置时,所需框和框会重叠raster
。
下图显示了两个框如何放置raster
但不声明grow to
选项:
现在有了您的原始设计:
虚线红色是使用show bounding box
选项得到的,红线是tcolorbox
框架。如您所见,bounding
框的位置正确,但由于tcolorboxes
不透明(colback=white
)并且使用的框大于其边界,右侧框覆盖了左侧框的一部分。
一种可能的解决方案是使用empty
皮肤,它不会在框周围或内部绘制任何内容,并使其内容透明。另一种解决方案是更改内框边距而不放大它。第一个选项产生
使用以下代码:
\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}
更新:
为了使盒子尽可能宽,最好使用size=minimal
(第 43 页),它可以构建没有填充或规则的盒子。EXAMPLE
盒子可以像这样声明:
\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}