1

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

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

2 Answers 2

5

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}

enter image description here

0
2

The answer by @user31729 already explained the cause of the problem. However there is a second way to avoid the problem:

Instead of using a different name, you could also use the noamsthm beamer class option which will tell beamer to not automatically define (amongst others) the example environment

\documentclass[noamsthm]{beamer}

\usepackage[most]{tcolorbox}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  outer arc=0pt,
  arc=0pt,
  colframe=blue,
  colback=blue!20,
  attach boxed title to top left,
  boxed title style={
    colback=blue,
    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=blue] 
      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=blue] 
      at (title.east) {#1};
  }
}


\begin{document}
\begin{frame}
\begin{example}{Test}
content...
\end{example}
\end{frame}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .