I'd like to create a tcolorbox
that looks like "example" sections in many textbooks, for example, something like the attached screenshot.
I found one sample code from an online source, which uses mdframed
. Yet I'd like to include as less packages as possible, thus wondering if there is ways to rewrite using tcolorbox
. Thank you!
The sample code is:
\newlength{\framedinnerleftmargin}
\newlength{\framedinnertopmargin}
\newlength{\framedreversedinnerleftmargin}
\setlength{\framedinnerleftmargin}{\widthof{Theoreme 10.10.10}+2em}
\setlength{\framedreversedinnerleftmargin}{\widthof{Theoreme 10.10.10}+1em}
\setlength{\framedinnertopmargin}{1em}
% first argument: label in upper left corner,
% second argument: background color
\newenvironment{boxedtext}[2]{\begin{mdframed}[%
hidealllines=true,%
backgroundcolor=#2,%
innertopmargin=\framedinnertopmargin,%
innerleftmargin=\framedinnerleftmargin,%
innerrightmargin=1em%
]%
\tabto{-\framedreversedinnerleftmargin}\textbf{#1}\tabto*{0em}%
}% begin code
{\hskip 0pt\\\hspace*{\fill}\end{mdframed}\vspace{1em}} % end code
\newenvironment{summary}[0]{\begin{center}\begin{minipage}[c]{\summarywidth}\begin{spacing}{0.9}\footnotesize} % begin code
{\end{spacing}\end{minipage}\end{center}} % end code
\newcounter{question}
% optional! if you want it to start at zero
% with every new chapter/section/etc.
\numberwithin{question}{section}
\newenvironment{question}[0]
{\refstepcounter{question}\vspace{1em plus 1em}\begin{boxedtext}{Question \thequestion.}{blue!7}}%\setlength{\parskip}{0em}}
{\end{boxedtext}\vspace{-1em plus 1em}}
\newenvironment{question*}[0]
{\vspace{1em plus 1em}\begin{boxedtext}{Question.}{blue!7}}
{\end{boxedtext}\vspace{-1em plus 1em}}