使用 tikz 绘制一个 tcolorbox

使用 tikz 绘制一个 tcolorbox

我在包中发现了一个不错的 tcolorbox。如何在 tikz 中重新绘制此框的标题?在此处输入图片描述

\begin{tcolorbox}[enhanced,title=My title,
    colframe=blue!50!black,colback=blue!10!white,colbacktitle=blue!5!yellow!10!white,
    fonttitle=\bfseries,coltitle=black,attach boxed title to top center=
    {yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
    boxed title style={boxrule=0.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;} }]
    \lipsum[2]
\end{tcolorbox}

答案1

您需要的所有内容都包含在您的代码中。它已经使用 Tikz 编写。

\documentclass[tikz,border=10]{standalone}
\colorlet{colframe}{blue!50!black}
\colorlet{colbacktitle}{blue!5!yellow!10!white}
\begin{document}
\begin{tikzpicture}
\node (A) at (0,0) {\phantom{Some text}};
\filldraw[colframe,line width=0.5mm] ([xshift=-4mm]A.west)
            -- (A.north west) -- (A.north east) -- ([xshift=4mm]A.east)
            -- (A.south east) -- (A.south west) -- cycle;
\fill[colbacktitle] ([xshift=-2mm]A.west)
            -- (A.north west) -- (A.north east)
            -- ([xshift=2mm]A.east) -- (A.south east) -- (A.south west)
            -- cycle;
\node at (A) {Some text};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容