Beamer 块颜色取决于部分

Beamer 块颜色取决于部分

我的 beamer 文件包含 4 个部分,每个部分都有一些块环境。我想创建一个命令,根据特定部分的编号定义该部分中块的颜色。我想我必须使用ifthen包:

\documentclass[]{beamer}
\usetheme{Madrid}
\usepackage{ifthen}
...
\newcommand{\myColor}{%
    \ifthenelse{\thesection = 1}{color1}{%
     \ifthenelse{\thesection = 2}{color2}{%
     \ifthenelse{\thesection = 3}{color3}{%
      \ifthenelse{\thesection = 3}{color4}{%
         DimGray}%
        }%
    }%
}%

\begin{document}
\section{first section}
\begin{frame}
    \begin{block}[A  block of the first section]
        Something about this example of the first kind.
    \end{block}
    \end{frame}
   \section{second section}
    \begin{frame}
    \begin{block}[A  block of the second section]
        Something about this example of the second kind.
    \end{block}

\end{frame}

\end{document}

但我不知道如何涉及block环境。任何建议都将不胜感激。

答案1

像这样吗?

\documentclass[]{beamer}
\usetheme{Madrid}

\AtBeginSection{%
    \ifnum\value{section}=1
        \setbeamercolor{block title}{bg=red}
    \fi
    \ifnum\value{section}=2
        \setbeamercolor{block title}{bg=green}
    \fi
}

\begin{document}
\section{first section}
\begin{frame}
    \begin{block}{A  block of the first section}
        Something about this example of the first kind.
    \end{block}
    \end{frame}
\section{second section}
    \begin{frame}
    \begin{block}{A  block of the second section}
        Something about this example of the second kind.
    \end{block}

\end{frame}

\end{document}

在此处输入图片描述


第二版

这种方法更接近您在问题中设想的语法。

\documentclass[]{beamer}
\usetheme{Madrid}

\definecolor{zz1}{rgb}{.8,.2,.2}
\definecolor{zz2}{rgb}{.7,.9,.1}
\definecolor{zz3}{rgb}{.6,.4,.8}

\AtBeginSection{%
   \setbeamercolor{block title}{bg=zz\thesection}
}

\begin{document}
\section{first section}
\begin{frame}
    \begin{block}{A  block of the first section}
        Something about this example of the first kind.
    \end{block}
    \end{frame}
\section{second section}
    \begin{frame}
    \begin{block}{A  block of the second section}
        Something about this example of the second kind.
    \end{block}
\end{frame}

\section{third section}
    \begin{frame}
    \begin{block}{A  block of the second section}
        Something about this example of the second kind.
    \end{block}
\end{frame}


\end{document}

相关内容