[Tex/LaTex] How to define a custom tcolorbox environment with color as a parameter


I want to use different colored tcolorboxes. Is there an easy way to avoid all that typing for every single box by using \newcommand or a macro?

title= More Test]
\item Test

Best Answer

The tcolorbox package provides a macro called \newtcolorbox to define custom environments; see section 2 in the manual (top of p12, in the current version). Under the assumption that you just want to change the colour, not the tints/shades, you could define a new environment that accepts three arguments (the first of which is optional):

  1. additional tcolorbox options
  2. box colour
  3. title

See below.

enter image description here



% new tcolorbox environment
% #1: tcolorbox options
% #2: color
% #3: box title
  colframe = #2!25,
  colback  = #2!10,
  coltitle = #2!20!black,  
  title    = {#3},


\begin{mybox}{red}{A red box}
\item Test

\begin{mybox}{green}{A green box}
\item Test

Related Question