1

I want to create new numbered tcolorbox environments, so that every group has its own numbering. I can do this by following code.

\usepackage[most]{tcolorbox}
\documentclass{article}
% group of alerts
\newtcolorbox[auto counter, number within=chapter]{alertbox}[1][]{
    colback=red!10!white,
    title=\textbf{Alert~\thetcbcounter :} {[#1]~},
}
% group of notes
\newtcolorbox[auto counter, number within=chapter]{notebox}[1][]{
    colback=blue!10!white,
    title=\textbf{Note~\thetcbcounter :} {[#1]~},
}
\begin{document}
   \begin{alertbox}[Food] % Alert 1.1: Food
        Food is ready
   \end{alertbox}
   \begin{alertbox}[Drinks] % Alert 1.2: Drinks
        Drinks are ready
   \end{alertbox}
   \begin{notebox}[Food] % Note 1.1: Food
        Caution! Food is hot.
   \end{notebox}
   \begin{notebox}[Drinks] % Note 1.2: Drinks
        There is Cola in Drinks!
   \end{notebox}

\end{document}

But, this leads to code repetition. I'm trying to avoid this by creating a command that constructs tcolorbox environment.

\newcommand{\declarenumberedbox}[3] {
   \newtcolorbox[auto counter, number within=chapter]{#1}[1][]{
       colback=#2,
       title=\textbf{#3~\thetcbcounter :} {[                            ]~},
                                          %% custom title must be here   %%
                                          %% what should be filled here? %%
   }
}
%% approximately how I want my code to look like 
%% (or some equivalent ways to achieve this).
\declarenumberedbox{alertbox}{Alert}{red!10!white}
\declarenumberedbox{notebox}{Note}{blue!10!white}

0 Answers0