在 Beamer 中有条件地继承颜色

在 Beamer 中有条件地继承颜色

我想更改fg中的项目符号的颜色beamer。在 中normal text它应该是黄色,但在 或 中exampleblockalertblock应该从 继承block title.fg。这是一个具有项目颜色默认定义的 NWE。

\documentclass{beamer}
\setbeamercolor{item}{parent=local structure}
\begin{document}
\begin{frame}
  \begin{itemize}
  \item xyz
  \end{itemize}
  \begin{block}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{block}
  \begin{exampleblock}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{exampleblock}
  \begin{alertblock}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{alertblock}
\end{frame}
\end{document}

答案1

begin您可以向环境的模板中添加颜色设置命令blockexampleblock如下alertblock所示:

\addtobeamertemplate{block begin}{\setbeamercolor{item}{fg=block title.fg}}{}

\addtobeamertemplate{block example begin}{\setbeamercolor{item}{fg=block title example.fg}}{}

\addtobeamertemplate{block alerted begin}{\setbeamercolor{item}{fg=block title alterted.fg}}{}

假设您希望它们与相应块标题的颜色相匹配。然后它们将否决您在这些环境中为项目颜色设置的任何全局值。

示例输出

\documentclass{beamer}

\setbeamercolor{item}{fg=yellow}

\addtobeamertemplate{block begin}{\setbeamercolor{item}{fg=block title.fg}}{}

\addtobeamertemplate{block example begin}{\setbeamercolor{item}{fg=block title example.fg}}{}

\addtobeamertemplate{block alerted begin}{\setbeamercolor{item}{fg=block title alerted.fg}}{}

\begin{document}

\begin{frame}
  \begin{itemize}
  \item xyz
  \end{itemize}
  \begin{block}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{block}
  \begin{exampleblock}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{exampleblock}
  \begin{alertblock}{abc}
    \begin{itemize}
    \item xyz
    \end{itemize}
  \end{alertblock}
\end{frame}

\end{document}

相关内容