我修改了答案这个帖子对于新块,如下所示,但是当我将显示的方程式放在第一行时,它会产生错误,Extra }, or forgotten $. ^^I\end{frame}
而当我将其放在空行之后时,错误就会消失。问题到底是什么?
我发现这个问题与Copenhagen
主题有关!
第一章数学align
环境产生不同的错误!
诗 2普通的区块不存在这样的问题!
\documentclass[]{beamer}
\usetheme{Copenhagen}
\newenvironment<>{theorem}[2][Theorem]{%
\setbeamercolor{block title}{fg=white,bg= red!90!blue}%
\begin{block}{#1}#3{#2}}{\end{block}}
\begin{document}
\begin{frame}
\begin{theorem}
this is OK!
\end{theorem}
\begin{theorem}%<-- error
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}%<-- OK
\[x^2=y^2+z^2\]
\end{theorem}
\begin{block}{theorem}%<-- OK
\[x^2=y^2+z^2\]
\end{block}
\end{frame}
\end{document}
我的目标是有一个带有一个可选参数的定理块,当它不为空时,它将成为块标题,如下所示:
\begin{theorem}
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}[MY TITLE]
\[x^2=y^2+z^2\]
\end{theorem}
答案1
\documentclass[]{beamer}
\usetheme{Copenhagen}
\newenvironment<>{theorem}[1][Theorem]{%
\setbeamercolor{block title}{fg=white,bg= red!90!blue}%
\begin{block}#2{#1}
}{
\end{block}
}
\begin{document}
\begin{frame}
\begin{theorem}<1->
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}<2->[MY TITLE]
\[x^2=y^2+z^2\]
\end{theorem}
\end{frame}
\end{document}
这里定义一个可选参数,其默认值为Theorem
。如果通过 指定了其他标题[MY TITLE]
,则将使用此标题。
感谢您的评论,它现在遵循覆盖规范。
答案2
无需重新设计轮子,只需使用 beamer 提供的默认定理环境即可。它可以很好地接受可选标题 - 无需进行任何更改。
\documentclass{beamer}
\usetheme{Copenhagen}
\begin{document}
\begin{frame}
\begin{theorem}
this is OK!
\end{theorem}
\begin{theorem}
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}[test]
\[x^2=y^2+z^2\]
\end{theorem}
\end{frame}
\end{document}
如果你不喜欢显示的可选标题()
,你可以更改theorem begin
模板:
\documentclass{beamer}
\usetheme{Copenhagen}
\makeatletter
\setbeamertemplate{theorem begin}
{%
\setbeamercolor{block title}{fg=white,bg=red!90!blue}%
\begin{\inserttheoremblockenv}
{%
\ifx\inserttheoremaddition\@empty
\inserttheoremname
\else
\inserttheoremaddition
\fi%
}%
}
\makeatother
\begin{document}
\begin{frame}
\begin{theorem}
this is OK!
\end{theorem}
\begin{theorem}
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}[test]
\[x^2=y^2+z^2\]
\end{theorem}
\begin{block}{title}
content...
\end{block}
\end{frame}
\end{document}