我的文档中有两种示例。我想使用不同的颜色,比如红色和蓝色。这就是我现在正在做的事情。
\documentclass[]{beamer}
\usetheme{Madrid}
\begin{document}
\begin{frame}
\frametitle{Test}
\setbeamercolor{block title}{fg=white,bg=red!75!black}
\begin{block}{First Kind Example}
This is example of the first kind.
\end{block}
\setbeamercolor{block title}{fg=white,bg=blue!75!black}
\begin{block}{Second Kind Example}
This is example of the second kind.
\end{block}
\end{frame}
\end{document}
setbeamercolor
我知道这有点愚蠢。我想定义两个新的块环境,每个颜色一个,这样每次使用时就不需要使用它们了。
\begin{block1}{First Kind Example}
...
\end{block1}
\begin{block2}{Second Kind Example}
...
\end{block2}
我知道我需要在序言中定义这两个新环境,但不知道如何做。谢谢您的帮助。
顺便问一下,关于 LaTeX/beamer 中的这些技巧,有什么好的参考资料吗?有什么推荐吗?
答案1
如果您想将它们作为示例呈现,并使用 beamer 的环境对它们进行标记example
(而不仅仅是使用通用的block
),您可以尝试如下操作:
\documentclass[]{beamer}
\usetheme{Madrid}
\newtheorem{examplefirst}{Example}
\newtheorem{examplesecond}{Example}
\newenvironment<>{examplefirst}[1][]{%
\setbeamercolor{block title example}{fg=white,bg=red!75!black}%
\begin{example}#2[#1]}{\end{example}}
\newenvironment<>{examplesecond}[1][]{%
\setbeamercolor{block title example}{fg=white,bg=blue!75!black}%
\begin{example}#2[#1]}{\end{example}}
\begin{document}
\begin{frame}
\begin{examplefirst}[An example of the first kind]
Something about this example of the first kind.
\end{examplefirst}
\begin{examplesecond}[An example of the second kind]
Something about this example of the second kind.
\end{examplesecond}
\begin{example}[A regular example]
Something about the regular example.
\end{example}
\end{frame}
\end{document}
生成结果:
如果你喜欢坚持使用通用block
环境,也许这样的事情可能会起作用:
\documentclass[]{beamer}
\usetheme{Madrid}
\newenvironment<>{examplefirst}[1]{%
\setbeamercolor{block title}{fg=white,bg=red!75!black}%
\begin{block}#2{#1}}{\end{block}}
\newenvironment<>{examplesecond}[1]{%
\setbeamercolor{block title}{fg=white,bg=blue!75!black}%
\begin{block}#2{#1}}{\end{block}}
\begin{document}
\begin{frame}
\begin{examplefirst}{An example of the first kind}
Something about this example of the first kind.
\end{examplefirst}
\begin{examplesecond}{An example of the second kind}
Something about this example of the second kind.
\end{examplesecond}
\begin{block}{A regular block}
Something in the regular block format.
\end{block}
\end{frame}
\end{document}
答案2
这是使用不同颜色的标准代码
\documentclass{beamer}
\usecolortheme{whale}
\usecolortheme{orchid}
\begin{document}
\begin{frame}{A frame}
\begin{block}{A block environment}
Some text.
\end{block}
\begin{alertblock}{An alertblock environment}
Some text.
\end{alertblock}
\begin{exampleblock}{An exampleblock environment}
Some text.
\end{exampleblock}
\end{frame}
\end{document}
答案3
@cfr 答案的扩展版本:
\newenvironment<>{definition}[2][DEFINITION]{%
\setbeamercolor{block title}{fg=white,bg= green}%
\setbeamerfont{block title example}{family=\ssfamily}
\begin{block}{#1}#3{#2}}{\end{block}}
并将其用作
\begin{definition}
some text
\end{definition}
其默认标题为:DEFINITION
或者您可以给出您的标题:
\begin{definition}[YOUR TITLE]
some text
\end{definition}