2

enter image description here enter image description here

My code

\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
%%%%%%%%
\newtheorem{ex}{Example}
%%%%%%%%



\AtBeginEnvironment{ex}{
    \begin{tcolorbox}[colframe=black,colback=blue!10,breakable,boxrule=0.5pt,sharp corners]
}
\AtEndEnvironment{ex}{

    \end{tcolorbox}

}
\begin{document}

\begin{ex}
    \lipsum[1]
\end{ex}    

\begin{ex}
    \lipsum[2]
\end{ex}

\begin{tcolorbox}[enhanced,title=Example 1,
    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[1]
\end{tcolorbox} 
\end{document}



3

You can declare a newtcbtheorem environment like in following code. For some more information about this command look at theorem section in tcolorbox documentation or in update section of this answer

\documentclass[12pt,a4paper,oneside]{book}
\usepackage{amsmath}
\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcbtheorem[number within=chapter]{ex}{Example}{%
    enhanced,
    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;}}
    }{ex}

\begin{document}

\begin{ex}{A nice example}{1}
    \lipsum[1]
\end{ex}    

\begin{ex}{}{}
As you can see in theorem~\ref{ex:1}

    \lipsum[2]
\end{ex}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.