我试图实现一个像这样的易碎的 tcolorbox:
\usepackage{geometry}
\usepackage{lipsum}
\usepackage[skins,breakable]{tcolorbox}
\newtcolorbox{cvbox}[2][]{
blanker,
%leftupper=4cm,
after skip=8mm,% enlarge distance to the next box
title=#2,
breakable,
fonttitle=\sffamily\bfseries,
coltitle=cyan,
%fontupper=\sffamily,%
%#1
overlay={%
\ifcase\tcbsegmentstate
% 0 = Box contains only an upper part
\or%
% 1 = Box contains an upper and a lower part
%\path[draw=red] (segmentation.west)--(frame.south east);
\else%
% 2 = Box contains only a lower part
%\path[draw=red] (frame.north west)--(frame.south east);
\fi%
}
#1
\begin{document}
Previous stuff...
\begin{tcolorbox}[breakable]
\begin{cvbox}{Esempio:}
long stuff...
\end{cvbox}
\end{tcolorbox}
有什么方法可以让 tcolorbox(灰色矩形)从第 25 页(就在之前的内容下方)开始,然后继续下一页?
答案1
嗯,您提供的代码不完整,所以我必须对其进行调整才能显示breakable tcolorbox
。您的代码包含一些特殊之处:
tcolorbox
当您随后将其放置在一般环境中时,为什么要定义一个新环境tcolorbox
呢?- 为什么要使用该
blanker
选项,因为它会删除环境的框架和填充颜色(除非这正是您想要的 - 那么为什么要使用环境tcolorbox
)? - 你定义中的第二个选项有什么用
cvbox
?我把它改成了1因为只有title
作为选项给出。
生成可破坏盒子的代码是:
\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage[skins,breakable]{tcolorbox}
\newtcolorbox{cvbox}[1][]{
enhanced,
% blanker, % <- removed as it suppresses box color and frame
%leftupper=4cm,
after skip=8mm,% enlarge distance to the next box
title=#1,
breakable = true,
fonttitle=\sffamily\bfseries,
coltitle=cyan,
colbacktitle=gray!10, % <- defines background color in title
titlerule= 0pt, % <- sets rule underneath title
%fontupper=\sffamily,%
%#1
overlay={%
\ifcase\tcbsegmentstate
% 0 = Box contains only an upper part
\or%
% 1 = Box contains an upper and a lower part
%\path[draw=red] (segmentation.west)--(frame.south east);
\else%
% 2 = Box contains only a lower part
%\path[draw=red] (frame.north west)--(frame.south east);
\fi%
}
colback = gray, % <- defines background color in box
colframe = black!75 % <- defines color of frame
}
\begin{document}
\section{Previous stuff...}
\lipsum[2-4]
% removed the tcolorbox environment
\begin{cvbox}[Esempio:]
long stuff...
\lipsum[5-8]
\end{cvbox}
\end{document}
上述代码的运行结果: