答案1
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usetikzlibrary{calc}
\newtcolorbox{contbox1}{enhanced,colback=white,frame code={%
\draw[dashed,line width=1pt,gray!50] (frame.south east) --
($(frame.south east)!0.3!(frame.south west)$);
\draw[line width=1pt,gray!50] ($(frame.south east)!0.3!(frame.south west)$)
-| (frame.north west) -| (frame.south east) ;
}}
\newtcolorbox{contbox2}{enhanced,colback=white,frame code={%
\draw[dashed,line width=1pt,gray!50] (frame.north west) --
($(frame.north west)!0.3!(frame.north east)$);
\draw[line width=1pt,gray!50] ($(frame.north west)!0.3!(frame.north east)$)
-| (frame.south east) -| (frame.north west);
}}
\begin{document}
\begin{contbox1}
Some text.
\end{contbox1}
\begin{contbox2}
Some more text.
\end{contbox2}
\end{document}
答案2
以下代码引入了一些更改用户237299解决方案。
- 仅声明了一个可破坏的 tcolorbox。
- 虚线片段被改变以绘制正确的角连接。
使用subskins
基于这个例子在tcolorbox
文档中。
\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%code for first part of broken box
skin first is subskin of={empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
},
%code for middle part of broken box
skin middle is subskin of={empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
},
%code for last part of broken box
skin last is subskin of={empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
},
},
#1
}
\begin{document}
\begin{contbox}
\lipsum[1-12]
\end{contbox}
\end{document}
更新:子皮肤选择
如果您需要强制执行盒子的某个方面,而不管可破坏盒子的哪个部分是独立的,则以下代码可以做到这一点。
它定义了三个subskins
,可选参数允许选择应用哪一个。默认情况下,应用可破坏盒子中的“正常”行为。
\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\usepackage{lipsum}
\tcbsubskin{myfirst}{empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mymiddle}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mylast}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);},
}
\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%skins for breakable boxes
skin first=myfirst,
skin middle=mymiddle,
skin last=mylast,
#1
}
\begin{document}
\begin{contbox}[skin=mylast]
\lipsum[2]
\end{contbox}
\begin{contbox}[skin=mymiddle]
\lipsum[2]
\end{contbox}
\begin{contbox}[skin=myfirst]
\lipsum[2]
\end{contbox}
\end{document}
第二次更新:使用magazine
库
由于 OP 似乎想要将盒子片段放入float
环境中,因此可以使用magazine
库在需要的地方打破盒子并自动选择相应的方面(第一个、中间、最后一个)。
以下示例将盒子破碎成 3cm 的碎片,并将每个碎片放入环境中figure
。可以看出,每个碎片都显示出与破碎盒子相对应的方面。
\documentclass{article}
\usepackage[skins, breakable, magazine]{tcolorbox}
\usepackage{lipsum}
\tcbsubskin{myfirst}{empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mymiddle}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mylast}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);},
}
\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%skins for breakable boxes
skin first=myfirst,
skin middle=mymiddle,
skin last=mylast,
reset box array,
store to box array,
#1
}
\begin{document}
\begin{contbox}[break at=3cm]
\lipsum[1-5]
\end{contbox}
\boxarraygetsize{\myfragments}
\begin{figure}
\centering
\consumeboxarray{1}
\caption{First fragment}
\end{figure}
\begin{figure}
\centering
\consumeboxarray{\myfragments}
\caption{Last fragment}
\end{figure}
\begin{figure}
\centering
\consumeboxarray{5}
\caption{One middle fragment}
\end{figure}
\end{document}