# Create a color box in beamer class

I did follow the instruction from Create a color box?, and succeed in the \documentclass{article}.

However, if I put the Tex code in the beamer class, it does not work. The code is:

\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,
},
fonttitle=\sffamily
}
}

> \newtcolorbox[auto counter,number within=section]{example}[1][]{
mystyle,
title=Example~\thetcbcounter,
overlay unbroken and first={
\node[anchor=west,font=\sffamily,color=myblue]
at (title.east) {#1};
}
}

\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
overlay unbroken and first={
\node[anchor=west,font=\sffamily,color=myblue]
at (title.east) {#1};
}
}


if I use "assumption" environment as designed in the above code only, it works well in the beamer class. However, if I create a slide with "assumption" environment (above code) in the beamer class, it does not work.

Any helps is highly appreciated.

Thanks

• Does not work is not really helpful. Please show us a MWE what you have done so far – user31729 Jun 23 '15 at 11:57

beamer already defines an example environment, so it's necessary to use another name, say myexample.

\documentclass{beamer}

\usepackage[most]{tcolorbox}

\definecolor{myblue}{rgb}{0,0,1.0}

\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,
},
fonttitle=\sffamily
}
}

\newtcolorbox[auto counter,number within=section]{myexample}[1][]{
mystyle,
title=Example~\thetcbcounter,
overlay unbroken and first={
\node[anchor=west,font=\sffamily,color=myblue]
at (title.east) {#1};
}
}

\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
overlay unbroken and first={
\node[anchor=west,font=\sffamily,color=myblue]
at (title.east) {#1};
}
}

\begin{document}

\begin{frame}

\begin{assumption}
Bla Blu Blo
\end{assumption}

\end{frame}

\end{document}