![可破坏的 tcolorbox,具有空/隐藏的内部和非空的框架](https://linux22.com/image/472435/%E5%8F%AF%E7%A0%B4%E5%9D%8F%E7%9A%84%20tcolorbox%EF%BC%8C%E5%85%B7%E6%9C%89%E7%A9%BA%2F%E9%9A%90%E8%97%8F%E7%9A%84%E5%86%85%E9%83%A8%E5%92%8C%E9%9D%9E%E7%A9%BA%E7%9A%84%E6%A1%86%E6%9E%B6.png)
我想定义一个可破坏的 tcolorbox,其内部不包含任何颜色或其他绘图代码,因此显示其背后的任何颜色。tcolorbox
该skins
库具有选项interior empty
和,interior hidden
它们控制内部的绘制,尽管我很难理解这些键和相应的frame empty
和之间的相互作用frame hidden
。我希望前一个键能够打印围绕盒子内容的框架,而不对内部进行任何处理,但盒子却打印了深灰色背景。
从这个答案frame empty
,我发现我们可以通过同时设置两者然后interior empty
用绘制框架来解决这个问题borderline
。这适用于未损坏的框,但如果框损坏,则似乎和frame empty
键interior empty
会被忽略,并且 tcolorbox 默认值会生效。
\documentclass{article}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{kantlipsum}
\pagecolor{yellow!10}
\tcbset{enhanced}
\begin{document}
\begin{tcolorbox}[
interior empty
]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[
interior empty,
frame empty % don't want hidden frame
]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[
interior hidden
]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[
interior hidden,
frame hidden, % don't want hidden frame
]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[
frame empty,
interior empty,
borderline={1pt}{0pt}{},
]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[
breakable,
frame empty,
interior empty,
borderline={1pt}{0pt}{},
]
This is a \textbf{tcolorbox}.
\kant[1-3]
\end{tcolorbox}
\end{document}
我可能误解了“框架”和“内部”的真正含义,但是有没有办法制作一个内部为空的可破坏的 tcolorbox 呢?
编辑
正如 samcarter_is_at_topanswers.xyz 在评论中指出的那样,“框架”是框后面的一个填充矩形,而不是在其周围绘制的线。这解释了 和 的interior empty
输出interior hidden
。
我还发现,总体而言,breakable
与以下交互不太好:frame empty
interior empty
\begin{tcolorbox}[
breakable,
interior empty,
frame empty
]
This is a \textbf{tcolorbox}.
\kant[1-5]
\end{tcolorbox}
当损坏时,这将重置框架和内部默认值。
就上下文而言,我正在尝试适应这个答案用于模拟thmbox
使用 tcolorbox 来使用页面背景颜色,而不是预设的背景颜色white
,因为这是 thmbox 的行为。
答案1
事实证明答案是阅读文档:)
通常,框架引擎会用颜色填充整个盒子区域,而其他引擎会用其他颜色填充某些区域。[...] 对于某些盒子,需要更精细的程序。例如,如果盒子应该是半透明的,已经涂漆的区域就不能不涂漆。因此,更精致的框架引擎会在框架上打孔,以便内部区域和可选的标题区域进行涂漆。由此产生的皮肤被称为拼图皮肤。
因此只需要使用拼图盒:
\documentclass{article}
\usepackage{xcolor}
\usepackage{pagecolor}
\pagecolor{yellow}
\usepackage[most]{tcolorbox}
\usepackage{kantlipsum}
\begin{document}
\begin{tcolorbox}[
enhanced jigsaw,
breakable,
opacityback=0,
]
This is a \textbf{tcolorbox}.
\kant[1-5]
\end{tcolorbox}
\end{document}
答案2
实际上,你可以让它透明,而不是让 tcolorbox看将其涂成与页面相同的颜色,使其透明:
\documentclass{article}
\usepackage{xcolor}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{kantlipsum}
\usepackage{pagecolor}
\pagecolor{yellow}
\tcbset{enhanced}
\begin{document}
\begin{tcolorbox}[
breakable,
colback=\thepagecolor
]
This is a \textbf{tcolorbox}.
\kant[1-5]
\end{tcolorbox}
\end{document}
答案3
虽然frame empty
和interior empty
在给定时不会按预期工作breakable
,但如果给定extras
密钥,它们就会起作用。这样我们就可以用伪造框架borderline
。
\documentclass{article}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{kantlipsum}
\pagecolor{yellow!10}
\begin{document}
\begin{tcolorbox}[
breakable,
extras={frame empty,interior empty},
borderline={1pt}{0pt}{}
]
This is a \textbf{tcolorbox}.
\kant[1-5]
\end{tcolorbox}
\end{document}
答案4
就上下文而言,我正在尝试适应这个答案用于模拟
thmbox
使用 tcolorbox 来使用页面背景颜色,而不是预设的背景颜色white
,因为这是 thmbox 的行为。
看来你需要
\tcbset{
thmbox/.style={
% ...
% colback=white,
% colframe=white,
% colbacktitle=white,
%% in order to imitate effect of "enhanced jigsaw, boxrule=0pt"
frame engine=empty,
interior titled engine=empty,
interior engine=empty,
extras broken={
frame engine=empty,
interior titled engine=empty,
interior engine=empty
},
% ...
}
}
完整示例,基于链接@Ignasi 的回答:
\documentclass{article}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{breakable, skins, theorems}
\pagecolor{yellow!10}
\tcbset{
thmbox/.style={
breakable,
enhanced,
sharp corners=all,
fonttitle=\bfseries\normalsize,
fontupper=\normalsize\itshape,
top=0mm,
bottom=0mm,
right=0mm,
% colback=white,
% colframe=white,
% colbacktitle=white,
%% in order to imitate effect of "enhanced jigsaw, boxrule=0pt".
%% or put the following three lines in "extras unbroken={...}"
frame engine=empty,
interior titled engine=empty,
%% every theorem has a title, so this is just for completeness
interior engine=empty,
extras broken={
frame engine=empty,
interior titled engine=empty,
interior engine=empty
},
coltitle=black,
attach boxed title to top left,
boxed title style={empty, size=minimal, bottom=1.5mm},
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
},
S/.style={thmbox,
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
},
L/.style={thmbox,
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);},
},
LQ/.style={thmbox,
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
\node[anchor=east] at (frame.south east) {$\square$};},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
\node[anchor=east] at (frame.south east) {$\square$};},
},
}
\newtcbtheorem[]{tcbthmbox}{Theorem}{thmbox}{theo}
\newtcbtheorem[]{tcbSthmbox}{Theorem}{thmbox,S}{theo}
\newtcbtheorem[]{tcbLthmbox}{Theorem}{thmbox,L}{theo}
\newtcbtheorem[]{proof}{Démonstration}{thmbox,LQ}{theo}
\begin{document}
\begin{tcbthmbox}{First result}{}
\lipsum[3]
\end{tcbthmbox}
\begin{tcbSthmbox}{Important}{}
\lipsum[2]
\end{tcbSthmbox}
\begin{tcbLthmbox}{Final}{}
\lipsum[1]
\end{tcbLthmbox}
\begin{proof}{Proof}{}
\lipsum[1]
\end{proof}
\end{document}