如何绘制带阴影效果的 tcolorbox

如何绘制带阴影效果的 tcolorbox

我需要绘制一个带有颜色阴影效果的矩形。请帮忙

实际结果

实际结果

预期结果

预期结果

以下是我的代码,请帮忙

    \documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}

\newtcolorbox{mybox}{
  colback=white!5!white,
  width=0.70\textwidth,
  left=3pt,
  right=3pt,
  top=3pt,
  bottom=3pt,
  skin=freelance,
  frame code={%
    \begin{pgfonlayer}{foreground}  
    \draw[line width = 1pt,color = white!30] ($(frame.south west) +(-1pt,-1pt)$) rectangle ($(frame.north east)+(1pt,1pt)$); %% outer rectangle
    \clip (frame.south west) rectangle (frame.north east);
    \draw[line width = 1pt,color=black!10!black,fill = white] (frame.south west) circle (7pt);
    \draw[line width = 1pt,color=black!10!black,fill = white] (frame.north west) circle (7pt);
    \draw[line width = 1pt,color=black!10!black,fill = white] (frame.north east) circle (7pt);
    \draw[line width = 1pt,color=black!10!black,fill = white] (frame.south east) circle (7pt);
      \draw[line width = 5pt,color=black!5!black]
           ($(frame.south west) +(0pt,7pt)$) -- ($(frame.north west)+(0pt,-7pt)$)  ; %% west
      \draw[line width = 1.8pt,color=black!5!black]
           ($(frame.north west) +(7pt,0pt)$) -- ($(frame.north east)+(-7pt,0pt)$)  ; %% north
      \draw[line width = 1.8pt,color=black!5!black]
           ($(frame.north east) +(0pt,-7pt)$) -- ($(frame.south east)+(0pt,7pt)$)  ; %% east
      \draw[line width = 1.8pt,color=black!5!black]
           ($(frame.south west) +(7pt,0pt)$) -- ($(frame.south east)+(-7pt,0pt)$)  ; %% south      
    \end{pgfonlayer}
  },
}


\begin{document}

\begin{mybox}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Cur-
abitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
\end{mybox}

\lipsum[1-10]

\end{document}

答案1

我想你想要这个吧?

\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{calc,shadows.blur}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newtcolorbox{mybox}{
  width=0.70\textwidth,
  left=3pt,
  right=3pt,
  top=3pt,
  bottom=3pt,
  skin=freelance,
  frame code={%
    \begin{pgfonlayer}{main}
      \path[fill=yellow!20,blur shadow={shadow xshift=4pt,shadow yshift=-4pt}] 
        ($(frame.north west)+(7pt,0)$) arc (0:-90:7pt) -- 
        ($(frame.south west)+(0,7pt)$) arc (90:0:7pt) -- 
        ($(frame.south east)+(-7pt,0)$) arc (180:90:7pt) -- 
        ($(frame.north east)+(0,-7pt)$) arc (270:180:7pt) -- cycle;
    \end{pgfonlayer}
  },
  interior code={%
    \path[draw,line width=1pt] 
      ($(frame.north west)+(7pt,0)$) arc (0:-90:7pt) -- 
      ($(frame.south west)+(0,7pt)$) arc (90:0:7pt) -- 
      ($(frame.south east)+(-7pt,0)$) arc (180:90:7pt) -- 
      ($(frame.north east)+(0,-7pt)$) arc (270:180:7pt) -- cycle;
  },
}


\begin{document}

\begin{mybox}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Cur-
abitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
\end{mybox}

\lipsum[1-10]

\end{document}

在此处输入图片描述

相关内容