带弧形边的 tcolorbox

带弧形边的 tcolorbox

我想使用tcolorbox一个填充的可破碎矩形来创建所有弯曲的边,例如

enter image description here

我无法正确填写。如果有人愿意帮忙,我将不胜感激。

答案1

这可以通过层和底层来实现。

可破碎性“困难” - 需要根据破碎序列中的位置重新绘制盒底和盒底(在tcolorbox客厅中:firstmiddlelast) - 这可以使用underlay first和来完成underlay middle and last,如果盒子没有破碎,则使用underlay unbroken

真实的内部背景tcolorbox根本没有被绘制,因此它不会绘制在下面的底层上。

可以使用新的 pgfkeys 更改内框和外框的颜色,如在 中所做的那样\tcbset

请注意,这可能会导致中断序列的最后一个框失败并产生令人捧腹的结果。

现在有了破损的盒子和改变颜色的能力:

\documentclass{article}

\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shapes.geometric,calc,backgrounds}


\newlength{\internalshift}
\setlength{\internalshift}{20pt}


\pgfdeclarelayer{background rounded rect}
\pgfsetlayers{background rounded rect,main}

\tcbset{%
  innerboxcolback/.colorlet=tcbcol@innerback,
  outerboxcolback/.colorlet=tcbcol@outerback,
  outerboxcolframe/.colorlet=tcbcol@outerboxframe,
  innerboxcolback=yellow,
  outerboxcolback=cyan!20,
  outerboxcolframe=blue,
}

\makeatletter
\newtcolorbox{curvedbox}[1][]{%
  enhanced,
  breakable,
  colback=blue!20,
  colframe=green,
  innerboxcolback=yellow,
  arc=\internalshift,
  auto outer arc,
  interior hidden,
  frame hidden,
  attach boxed title to top center,
  boxed title style={colback=tcbcol@outerback,enhanced,frame hidden},
  coltitle=black,
  title={Title},
  underlay={% Drawing the blue 
    \begin{pgfonlayer}{background rounded rect}
      \draw[tcbcol@outerboxframe, line width=1.5pt, fill=tcbcol@outerback,rounded corners=1.5\internalshift] ($(frame.north west) + (0pt,1\internalshift)$)  rectangle ($(frame.south east) - (0pt,\internalshift)$);
      \draw[tcbcol@outerboxframe, line width=1.5pt,fill=tcbcol@outerback,rounded corners=1.5\internalshift] ($(frame.north west) - (0.5\internalshift,0.5\internalshift)$) rectangle ($(frame.south east) + (0.5\internalshift,0.5\internalshift)$);
    \end{pgfonlayer}
  },% End of underlay 
  % Now the yellow box underlay if the box is unbroken
  underlay unbroken={\draw[tcbcol@frame, line width=1.5pt, fill=tcbcol@innerback,rounded corners=\kvtcb@arc] (frame.north west)  rectangle (frame.south east);},
  % Now the yellow box underlay if the box is broken, provide rounded rectangles for the first at the bottom and for the middle and last on the top. 
  underlay first={\draw[tcbcol@frame, line width=1.5pt, fill=tcbcol@innerback,rounded corners=\kvtcb@arc] (frame.north west)  rectangle (frame.south east);},
  underlay middle and last={\draw[tcbcol@frame, line width=1.5pt, fill=tcbcol@innerback,rounded corners=\kvtcb@arc] (frame.north west)  rectangle (frame.south east);},
    #1
}
\makeatother


\begin{document}

\begin{curvedbox}
  \blindtext[10]
\end{curvedbox}
\end{document}

enter image description here

相关内容