在 Beamer 中,块内和块外部的条目使用不同的颜色吗?

在 Beamer 中,块内和块外部的条目使用不同的颜色吗?

我希望获得我在以下 MWE 中描述的内容,即符号itemize应该是

  • 黑色外部块;
  • 蓝色普通的块;
  • 警报块中为红色;
  • 示例块中为绿色。

梅威瑟:

\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{itemize} 
\item Here in blue, I'd like it in black. 
\end{itemize}
\begin{block}{A block}
  \begin{itemize} 
  \item Here in blue, I'd like keep it in blue. 
  \end{itemize}
\end{block}
\begin{alertblock}{An alert block}
  \begin{itemize} 
  \item Here in red, I'd like keep it in red. 
  \end{itemize}
\end{alertblock}
\begin{exampleblock}{An example block}
  \begin{itemize} 
  \item Here in green, I'd like keep it in green. 
  \end{itemize}
\end{exampleblock}
\end{frame}
\end{document}

最小工作示例

如果我查看beamercolorthemedefault.sty,我会看到items 使用以下颜色进行着色local structure

  • 如果我把 改为local structure黑色,普通的块变黑;
  • 如果我直接将item颜色改为黑色,那么所有块都是黑色。

那么,获得期望结果的正确方法是什么?

答案1

我会将普通文本的颜色设置local structure为黑色,然后在启动普通块时将其更改为再次匹配的颜色structure。这可以通过将颜色的重新定义添加到 beamer 模板来实现block begin

\documentclass{beamer}

\setbeamercolor{local structure}{parent=normal text}
\addtobeamertemplate{block begin}{\setbeamercolor{local structure}{parent=structure}}{}

\begin{document}
\begin{frame}
\begin{itemize} 
\item Here in blue, I'd like it in black. 
\end{itemize}
\begin{block}{A block}
  \begin{itemize} 
  \item Here in blue, I'd like keep it in blue. 
  \end{itemize}
\end{block}
\begin{alertblock}{An alert block}
  \begin{itemize} 
  \item Here in red, I'd like keep it in red. 
  \end{itemize}
\end{alertblock}
\begin{exampleblock}{An example block}
  \begin{itemize} 
  \item Here in green, I'd like keep it in green. 
  \end{itemize}
\end{exampleblock}
\end{frame}
\end{document}

示例代码的输出,其中项目符号用黑色、蓝色、红色和绿色标出

答案2

在此处输入图片描述

一种可能性是设置itemize item颜色设置为黑色。这将影响全部环境itemize,然后借助包,etoolbox您可以恢复块内的所需颜色:

\usepackage{etoolbox}
\setbeamercolor{itemize item}{fg=black}
\AtBeginEnvironment{block}{\setbeamercolor{itemize item}{fg=structure}}
\AtBeginEnvironment{alertblock}{\setbeamercolor{itemize item}{fg=block title alerted.fg}}
\AtBeginEnvironment{exampleblock}{\setbeamercolor{itemize item}{fg=block title example.fg}}

完整示例:

\documentclass{beamer}
\usepackage{etoolbox}

\setbeamercolor{itemize item}{fg=black}
\AtBeginEnvironment{block}{\setbeamercolor{itemize item}{fg=structure}}
\AtBeginEnvironment{alertblock}{\setbeamercolor{itemize item}{fg=block title alerted.fg}}
\AtBeginEnvironment{exampleblock}{\setbeamercolor{itemize item}{fg=block title example.fg}}

\begin{document}
\begin{frame}
\begin{itemize} 
\item Here in black, as desired. 
\end{itemize}
\begin{block}{A block}
  \begin{itemize} 
  \item Here in blue, I'd like keep it in blue. 
  \end{itemize}
\end{block}
\begin{alertblock}{An alert block}
  \begin{itemize} 
  \item Here in red, I'd like keep it in red. 
  \end{itemize}
\end{alertblock}
\begin{exampleblock}{An example block}
  \begin{itemize} 
  \item Here in green, I'd like keep it in green. 
  \end{itemize}
\end{exampleblock}
\end{frame}
\end{document}

相关内容