这是我的 MWE:
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins,hooks}
\newtcolorbox{mybox}[2][]{enhanced,
frame code app={\draw[yellow,line width=1cm] (frame.south west)--(frame.north east);},
interior titled code app={\draw[red,line width=1cm] (frame.north west)--(frame.south east);},
leftrule=3mm,
arc=4mm,
colframe=blue!80!red,colback=white,colbacktitle=blue!5!yellow!50!white,
fonttitle=\bfseries,coltitle=black,
attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=.5mm,frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)-- (frame.south east) -- (frame.south west) -- cycle; },interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east)-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} },
title={#2},#1}
\newtcolorbox{mybox2}[2][]{enhanced,
frame code app={\draw[yellow,line width=1cm] (frame.south west)--(frame.north east);},
interior titled code app={\draw[red,line width=1cm] (frame.north west)--(frame.south east);},
leftrule=3mm,
arc=4mm,
colframe=blue!80!red,colback=white,colbacktitle=blue!5!yellow!50!white,
fonttitle=\bfseries,coltitle=black,
% attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=.5mm,frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)-- (frame.south east) -- (frame.south west) -- cycle; },interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east)-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} },
title={#2},#1}
\begin{document}
\begin{mybox}{Studied systems}
\lipsum[1]
\end{mybox}
\lipsum[1]
\begin{mybox2}{Studied systems2}
\lipsum[1]
\end{mybox2}
\end{document}
它给:
我也想让红线穿过第一个 tcolorbox。我发现attach boxed title to top center
代码可以产生红线消失的效果。
这个问题的解决方案是什么?
答案1
和frame code app
是interior titled code app
相当低级的选项。interior titled code app
添加用于绘制带有标题的框内部的代码。全部方框标题版本将标题从主框中分离出来,并将其放入自己的框中。这意味着,主框将被视为没有标题的框。因此,interior titled code app
没有效果,因为它仅用于有标题的框(在低级意义上)。
一个可能的解决方案是替换interior titled code app
为interior code app
:
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins,hooks}
\newtcolorbox{mybox}[2][]{enhanced,
frame code app={\draw[yellow,line width=1cm] (frame.south west)--(frame.north east);},
interior code app={\draw[red,line width=1cm] (frame.north west)--(frame.south east);},
leftrule=3mm,
arc=4mm,
colframe=blue!80!red,colback=white,colbacktitle=blue!5!yellow!50!white,
fonttitle=\bfseries,coltitle=black,
attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=.5mm,frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)-- (frame.south east) -- (frame.south west) -- cycle; },interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east)-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} },
title={#2},#1}
\begin{document}
\begin{mybox}{Studied systems}
\lipsum[1]
\end{mybox}
\end{document}
得出:
或者,由于红线交叉点位于框顶部,您可以使用overlay
或underlay
选项,这些选项更高级且独立于标题设置。