Beamer a plusieurs des blocs différents (block, alertblock, exampleblock, theorem, proof, ...). Comment modifier la couleur des blocs ?

Posée 18 Avr '19, 17:56

samcarter's gravatar image

samcarter
8.4k2817
Taux d'acceptation : 56%

Modifiée 19 Avr '19, 19:41

Pathe's gravatar image

Pathe ♦♦
7.5k42204251


Pour les blocs normaux (block, alertblock, exampleblock) c'est facile, on peut faire :

Ouvrir dans l'éditeur Overleaf
% block
\setbeamercolor{block title}{fg=blue,bg=blue!20!bg}
\setbeamercolor{block body}{bg=block title.bg!30!bg}

% alertblock
\setbeamercolor{block title alerted}{fg=white,bg=red!75!black}
\setbeamercolor{block body alerted}{bg=block title alerted.bg!10!bg}

% exampleblock
\setbeamercolor{block title example}{fg=white,bg=green!75!black}
\setbeamercolor{block body example}{bg=block title example.bg!10!bg}

Pour les blocs de théorème, c'est plus difficile. Normalement, ils ont la même couleur que block ou exampleblock ; mais avec un peu de travail :

Ouvrir dans l'éditeur Overleaf
\documentclass{beamer}

% block
\setbeamercolor{block title}{fg=black,bg=green!50!black}
\setbeamercolor{block body}{fg=green!50!black,bg=green!50!black!30!white}

% alertblock
\setbeamercolor{block title alerted}{fg=black,bg=green!50!white}
\setbeamercolor{block body alerted}{fg=green,bg=green!30!white}

% exampleblock
\setbeamercolor{block title example}{fg=black,bg=lime!50!white}
\setbeamercolor{block body example}{fg=lime,bg=lime!30!white}

% theorem
\BeforeBeginEnvironment{theorem}{
  \setbeamercolor{block title}{fg=black,bg=yellow!50!white}
  \setbeamercolor{block body}{fg=yellow,bg=yellow!30!white}
}
\AfterEndEnvironment{theorem}{
    \setbeamercolor{block title}{fg=blocktitlefgsave,bg=blocktitlebgsave}
    \setbeamercolor{block body}{fg=blockbodyfgsave,bg=blockbodybgsave}
}

% corollary
\BeforeBeginEnvironment{corollary}{
  \setbeamercolor{block title}{fg=black,bg=orange!50!white}
  \setbeamercolor{block body}{fg=orange, bg=orange!30!white}
}
\AfterEndEnvironment{corollary}{
    \setbeamercolor{block title}{fg=blocktitlefgsave,bg=blocktitlebgsave}
    \setbeamercolor{block body}{fg=blockbodyfgsave,bg=blockbodybgsave}
}

% definition
\BeforeBeginEnvironment{definition}{
  \setbeamercolor{block title}{fg=black,bg=red!50!white}
  \setbeamercolor{block body}{fg=red, bg=red!30!white}
}
\AfterEndEnvironment{definition}{
    \setbeamercolor{block title}{fg=blocktitlefgsave,bg=blocktitlebgsave}
    \setbeamercolor{block body}{fg=blockbodyfgsave,bg=blockbodybgsave}
}

% definitions
\BeforeBeginEnvironment{definitions}{
  \setbeamercolor{block title}{fg=black,bg=violet!50!white}
  \setbeamercolor{block body}{fg=violet, bg=violet!30!white}
}
\AfterEndEnvironment{definitions}{
    \setbeamercolor{block title}{fg=blocktitlefgsave,bg=blocktitlebgsave}
    \setbeamercolor{block body}{fg=blockbodyfgsave,bg=blockbodybgsave}
}

% fact
\BeforeBeginEnvironment{fact}{
  \setbeamercolor{block title}{fg=black,bg=blue!50!white}
  \setbeamercolor{block body}{fg=blue, bg=blue!30!white}
}
\AfterEndEnvironment{fact}{
    \setbeamercolor{block title}{fg=blocktitlefgsave,bg=blocktitlebgsave}
    \setbeamercolor{block body}{fg=blockbodyfgsave,bg=blockbodybgsave}
}

% example
\BeforeBeginEnvironment{example}{
  \setbeamercolor{block title example}{fg=black,bg=cyan!50!white}
  \setbeamercolor{block body example}{fg=cyan, bg=cyan!30!white}
}
\AfterEndEnvironment{example}{
    \setbeamercolor{block title example}{fg=exblocktitlefgsave,bg=exblocktitlebgsave}
    \setbeamercolor{block body example}{fg=exblockbodyfgsave,bg=exblockbodybgsave}
}

% examples
\BeforeBeginEnvironment{examples}{
  \setbeamercolor{block title example}{fg=black,bg=teal!50!white}
  \setbeamercolor{block body example}{fg=teal, bg=teal!30!white}
}
\AfterEndEnvironment{examples}{
    \setbeamercolor{block title example}{fg=exblocktitlefgsave,bg=exblocktitlebgsave}
    \setbeamercolor{block body example}{fg=exblockbodyfgsave,bg=exblockbodybgsave}
}

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

\begin{document}

\usebeamercolor{block title}
\colorlet{blocktitlefgsave}{block title.fg} 
\colorlet{blocktitlebgsave}{block title.bg}
\usebeamercolor{normal text}
\usebeamercolor{block body}
\colorlet{blockbodyfgsave}{block body.fg}
\colorlet{blockbodybgsave}{block body.bg}   
\usebeamercolor{normal text}

\usebeamercolor{block title example}
\colorlet{exblocktitlefgsave}{block title example.fg}   
\colorlet{exblocktitlebgsave}{block title example.bg}
\usebeamercolor{normal text}
\usebeamercolor{block body example}
\colorlet{exblockbodyfgsave}{block body example.fg}
\colorlet{exblockbodybgsave}{block body example.bg} 
\usebeamercolor{normal text}

\begin{frame}[allowframebreaks]

% normal blocks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

    \begin{alertblock}{my alertblock}
            An alertblock
    \end{alertblock}

    \begin{exampleblock}{my exampleblock}
            An exampleblock
    \end{exampleblock}

% theorem blocks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

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

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

    \begin{definitions}[My definitions]
        Some definitions.
    \end{definitions}

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

    \begin{example}[My example]
        An example.
    \end{example}

    \begin{examples}[My examples]
        Some examples.
    \end{examples}

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

% testing normal blocks again

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

    \begin{exampleblock}{my exampleblock}
            An exampleblock
    \end{exampleblock}

\end{frame}
\end{document}
Lien permanent

Publiée 18 Avr '19, 17:57

samcarter's gravatar image

samcarter
8.4k2817
Taux d'acceptation : 56%

Modifiée 19 Avr '19, 19:44

Pathe's gravatar image

Pathe ♦♦
7.5k42204251

Votre réponse
(dés)activer l'aperçu

Suivre cette question

Par courriel :

Une fois que vous serez enregistré, vous pourrez souscrire à n'importe quelle mise à jour ici

Par flux RSS :

Réponses

Réponses et commentaires

Bases de Markdown

  • *italique* ou _italique_
  • **gras** ou __gras__
  • Lien ::[texte](http://url.com/ "Titre ")
  • Image : ?![alt texte](/path/img.jpg "Titre ")
  • Liste numérotée : 1. Foo 2. Bar
  • Pour ajouter un passage à la ligne, ajoutez deux espaces à l'endroit où vous souhaitez que la ligne commence.
  • Les balises HTML de base sont également prises en charge.