1

My beamer file contain 4 section and in any section some block environment. I would like to create a command that defines a color for block of in specific section depending on the number of that section. I think I must use ifthen package:

\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}

but I don't know how to involve block environment. any suggestion would be appreciate.

5

Something like this?

\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}

enter image description here


Second version

This approach is a bit closer to the syntax you envisioned in your question.

\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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.