I am a new learner in LaTeX and want to add label for referencing to the below code done in tcolorbox
. This program example was provided by @Gonzalo Medina in his improved version where both tcbcounter
and optional title is included.
I need a label option for both examples and assumptions.
Actually, after each section, I would be using blocks example and assumptions for each section so an option to also add current section title in the optional title text would be additionally of much help.
\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{myblue}{RGB}{0,163,243}
\tcbset{mystyle/.style={
breakable,
enhanced,
outer arc=0pt,
arc=0pt,
colframe=myblue,
colback=myblue!20,
attach boxed title to top left,
boxed title style={
colback=myblue,
outer arc=0pt,
arc=0pt,
top=3pt,
bottom=3pt,
},
fonttitle=\sffamily
}
}
\newtcolorbox[auto counter,number within=section]{example}[1][]{
mystyle,
title=Example~\thetcbcounter,
overlay unbroken and first={
\path
let
\p1=(title.north east),
\p2=(frame.north east)
in
node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
at (title.east) {#1};
}
}
\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
overlay unbroken and first={
\path
let
\p1=(title.north east),
\p2=(frame.north east)
in
node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
at (title.east) {#1};
}
}
\begin{document}
\section{Test section}
\begin{example}
test
\end{example}
\begin{assumption}
test
\end{assumption}
\begin{example}[Optional title]
test
\end{example}
\begin{assumption}[Optional title with some more words for the example so it spans two lines]
test
\end{assumption}
\end{document}