两个带有 tcolorbox 的盒子

两个带有 tcolorbox 的盒子

在以下两段代码中,我想在右上角包含一个标题,并为语句添加一个计数器。

我也想在环境中拥有这个标题......

\documentclass[a4paper]{article}
\setlength{\parindent}{0pt}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{titleboxcolor}{RGB}{200,200,200}
\newcommand{\titlepath}{
  \fill[titleboxcolor]
  (title.south east)
  --(title.east)coordinate(A)
  to[curve to,out=90,in=0]($(A)+(-5mm,5mm)$)
      --($(title.north west)+(5mm,0mm)$)coordinate(B)
to[curve to,out=180,in=90]($(B)+(-5mm,-5mm)$)coordinate(C)
      --($(C)+(0mm,-5mm)$)
      to[curve to,out=90,in=180]($(title.south west)+(+5mm,0mm)$)coordinate(F)
      --cycle;
      \draw[titleboxcolor,draw=none]%ultra thick
      ([yshift=0.5\pgflinewidth]title.south east)--
      ([yshift=0.5\pgflinewidth]title.south-|interior.east);
    }
\newtcolorbox{myenvironment}{
  enhanced,
  %frame empty,
  colframe=titleboxcolor,
  title=Example,
  colback=yellow!10,
  coltitle=black,
  attach boxed title to top left={xshift=0mm},
  boxed title style={empty},
  underlay boxed title=\titlepath
}
\begin{document}
Before... 
\begin{myenvironment}
My example 1 here... 
\end{myenvironment}
... 
\begin{myenvironment}
My example 2 here... 
\end{myenvironment}
After... 
\end{document}

\documentclass[a4paper]{article}
\setlength{\parindent}{0pt}
\usepackage[most]{tcolorbox}
\makeatletter
\newtcolorbox{mybox}[2][]{
        enhanced, 
        breakable,
        sharp corners,
        rounded corners=northwest,
        colback=white,
        colframe=black!30,
        fonttitle=\bfseries\large\sffamily,
        %frame hidden,
        title=#2,
        attach boxed title to top left,
        boxed title size=standard,
        boxed title style={%
                empty,
                rounded corners=north, 
                boxrule=0pt,
                bottom=0pt,
        },
          underlay boxed title={%
                \filldraw[rounded corners=\kvtcb@arc, black!30, line width=.5mm]
                    (title.south east)--++(93:\tcboxedtitleheight)--++(183:\tcboxedtitlewidth)--++(-87:\tcboxedtitleheight)|-cycle;
                \draw[tcbcolframe, line width=.5mm] (title.south)|-(frame.north east);
                },
        #1
    }
\makeatother
\begin{document}
Before... 
\begin{mybox}{Example}
My Example 1 here... 
\end{mybox}
... 
\begin{mybox}{Example}
My example 2 here... 
\end{mybox}
After...
\end{document}

非常感谢你的帮助。


我希望它看起来像这样:

谢谢 !

答案1

对于第二个代码集

在此处输入图片描述

\documentclass[a4paper]{article}
\setlength{\parindent}{0pt}
\usepackage[most]{tcolorbox}
\makeatletter
\newtcolorbox{mybox}[2][]{
    enhanced, 
    breakable,
    sharp corners,
    rounded corners=northwest,
    colback=white,
    colframe=black!30,
    fonttitle=\bfseries\large\sffamily,
    %frame hidden,
    title=#2,
    attach boxed title to top left,
    boxed title size=standard,
    boxed title style={%
        empty,
        rounded corners=north, 
        boxrule=0pt,
        bottom=0pt,
    },
    underlay boxed title={%
        \filldraw[rounded corners=\kvtcb@arc, black!30, line width=.5mm]
        (title.south east)--++(93:\tcboxedtitleheight)--++(183:\tcboxedtitlewidth)--++(-87:\tcboxedtitleheight)|-cycle;
        \draw[tcbcolframe, line width=.5mm] (title.south)|-(frame.north east);
        \path[fill=black!30,line width=.4mm] (frame.north east)--++(1pt,0)coordinate(n3)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
        \node at ([shift={(-8mm,4mm)}]frame.north east){\itshape\textbf{\sffamily MyTitle}};
    },
    #1
}
\makeatother
\begin{document}
    Before... 
    \begin{mybox}{Example}
        My Example 1 here... 
    \end{mybox}
    ... 
    \begin{mybox}{Example}
        My example 2 here... 
    \end{mybox}
    After...
\end{document}

相关内容