基于慕子老师的这个回答,不借助任何已有的轮子(如borderline等),基于subskin可以把整个边框路径视为一个整体,可以有如下的实现:
\documentclass{article}
\usepackage[papersize={15cm, 6cm}, margin=.3in]{geometry}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{breakable, skins, theorems}
\tikzset{
mybox frame/.style={
tcbcolframe, line width=1.5pt, line cap=round
}
}
\tcbsubskin{mybox}{empty}{
frame engine=path,
enlarge top by=1ex,
fonttitle=\bfseries\Large\sffamily,
% make title another tcolorbox, in natual width
attach boxed title to top left={
xshift=3em,
yshift=-\tcboxedtitleheight/2+2pt,
yshifttext=-\tcboxedtitleheight/2+2pt
},
boxed title style={
skin=empty,
% frame code={
% \draw[red] (frame.north west) rectangle (frame.south east);
% }
},
% frame code specific for unbroken boxes
frame code={
\draw[mybox frame]
([yshift=-2pt]title.west) -| (frame.south west) -| (frame.north east)
([yshift=-2pt]title.east) -- ++(3em,0)
;
},
% frame code for broken boxes
skin first is subskin of={emptyfirst}{
frame code={
\draw[mybox frame]
([yshift=-2pt]title.west) -| (frame.south west)
(frame.south east) -- (frame.north east)
([yshift=-2pt]title.east) -- ++(3em,0)
;
}
},
skin middle is subskin of={emptymiddle}{
frame code={
\draw[mybox frame]
(frame.north east) -- (frame.south east)
(frame.north west) -- (frame.south west);
}
},
skin last is subskin of={emptylast}{
frame code={
\draw[mybox frame]
(frame.north east)
-- (frame.south east)
-- (frame.south west)
-- (frame.north west);
}
}
}
\NewTColorBox[
auto counter,
number within=chapter
]{mytcbbox}{O{black}m}{
breakable,
skin=mybox,
colframe=#1,
coltitle=#1,
title=#2,
}
\begin{document}
\section{Using subskin, unbroken box}
\begin{mytcbbox}{This is a theorem}
\lipsum[1][1-5]
\end{mytcbbox}
\section{Using subskin, broken box}
\begin{mytcbbox}[violet]{This is another theorem}
\lipsum[1-2]
\end{mytcbbox}
\end{document}
至于\Cref或者\Doubleref的问题,不是本问题的重点,应该开新的提问。
























问 tcolorbox 实现某种特定的边框