在 beamer 类中创建颜色框

在 beamer 类中创建颜色框

我确实遵循了创建一个彩色盒子?并取得成功\documentclass{article}

但是,如果我将 Tex 代码放入类中beamer,它不起作用。代码是:

\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};
  }
}

如果我仅使用上述代码中设计的“假设”环境,它在 beamer 类中可以正常工作。但是,如果我在 beamer 类中创建带有“假设”环境(上述代码)的幻灯片,它就不起作用。

非常感谢您的帮助。

谢谢

答案1

beamer已经定义了一个example环境,因此有必要使用另一个名称,比如说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}

在此处输入图片描述

答案2

@user31729 的回答已经解释了问题的原因。但是还有第二种方法可以避免这个问题:

除了使用不同的名称外,您还可以使用noamsthmbeamer 类选项,它将告诉 beamer 不要自动定义(除其他外)example环境

\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}

相关内容