11

In a beamer presentation, I’d like to set up different colors for normal blocks, definition blocks, theorem blocks, proof blocks, example blocks…

Ideally I’d set those up using \usebeamercolor commands. I can do it for example blocks, and for all other kinds of blocks at once, as illustrated in the sample below (compiled using XeLaTeX). But I can’t find how to do it for specific, non-example, types of blocks.

I suppose “Custom beamer blocks for pros and cons” points towards some solution, but I’d prefer (somehow) inheriting from the existing special block environment definitions rather than define new environments from scratch.

\documentclass{beamer}
\usepackage{fontspec}

\useinnertheme[shadow=true]{rounded}

\setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg}

\setbeamercolor{block title example}{use=example text,fg=example text.fg,bg=example text.fg!20!bg}
\setbeamercolor{block body example}{parent=normal text,use=block title example,bg=block title example.bg!50!bg}

\begin{document}
\begin{frame}
    \begin{block}{My block}
        A block.
    \end{block}
    \begin{definition}[My definition]
        A definition.
    \end{definition}
    \begin{theorem}[My theorem]
        A theorem.
    \end{theorem}
    \begin{proof}[My proof]
        A proof.
    \end{proof}
    \begin{example}[My example]
        An example.
    \end{example}
\end{frame}
\end{document}

migrated from stackoverflow.com Jan 5 '17 at 14:04

This question came from our site for professional and enthusiast programmers.

16
\documentclass{beamer}

\useinnertheme[shadow=true]{rounded}

\usepackage{etoolbox}

\setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg}

\setbeamercolor{block title example}{use=example text,fg=example text.fg,bg=example text.fg!20!bg}
\setbeamercolor{block body example}{parent=normal text,use=block title example,bg=block title example.bg!50!bg}

\addtobeamertemplate{proof begin}{%
    \setbeamercolor{block title}{fg=black,bg=red!50!white}
    \setbeamercolor{block body}{fg=red, bg=red!30!white}
}{}

\BeforeBeginEnvironment{theorem}{
    \setbeamercolor{block title}{fg=black,bg=orange!50!white}
    \setbeamercolor{block body}{fg=orange, bg=orange!30!white}
}
\AfterEndEnvironment{theorem}{
 \setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
 \setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg, fg=black}
}

\BeforeBeginEnvironment{definition}{%
    \setbeamercolor{block title}{fg=black,bg=pink!50!white}
    \setbeamercolor{block body}{fg=pink, bg=pink!30!white}
}
\AfterEndEnvironment{definition}{
 \setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
 \setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg, fg=black}
}

\begin{document}
\begin{frame}
    \begin{block}{My block}
        A block.
    \end{block}

    \begin{definition}[My definition]
        A definition.
    \end{definition}

    \begin{theorem}[My theorem]
        A theorem.
    \end{theorem}
    \begin{proof}[My proof]
        A proof.
    \end{proof}
    \begin{example}[My example]
        An example.
    \end{example}

    \begin{block}{My block}
        A block.
    \end{block}    

\end{frame}
\end{document}

enter image description here

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.