I want to customize block (alertblock) in Beamer. I want a transparent block, with a red frame and where the title is also in red like the one given in the image below:
MWE:
\documentclass[12 pt]{beamer}
\usetheme{default}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T1]{fontenc} % pour taper les lettres accentues
\usepackage[latin1]{inputenc}
\usepackage[frenchb]{babel}
\usepackage[babel=true]{csquotes} % csquotes va utiliser la langue dÈfinie dans babel
\frenchbsetup{StandardLists=true}
%%%%%%%%%%
% FONTS %
%%%%%%%%%%
%% Default font: lmodern, doesn't require fontspec % solves some default warnings
%\usepackage[T1]{fontenc}
%\usepackage{lmodern}
%\usepackage{sfmath} % Sans Serif Math, off by default
%% Protects fonts from Beamer screwing with them
%% http://tex.stackexchange.com/questions/10488/force-computer-modern-in-math-mode
\usefonttheme{professionalfonts}
%% XeLaTeX fonts: (comment out if you don't use XeLaTeX)
%% For advanced fonts: access local OS X fonts
\usepackage[no-math]{fontspec}
%% This template uses typical OS X and Adobe fonts
\defaultfontfeatures{Mapping=tex-text} % This seems to be important for mapping glyphs properly
\setmainfont{Chalkboard} % Beamer ignores "main font" in favor of sans font
\setsansfont{Chalkboard} % This is the font that beamer will use by default
% \setmainfont{Gill Sans Light} % Prettier, but harder to read
\setbeamerfont{title}{family=\fontspec{Chalkduster}}
%\newcommand{\handwriting}{\fontspec{augie}} % From Emerald City, free font
% \newcommand{\handwriting}{} % If you prefer no special handwriting font or don't have augie
%% Gill Sans doesn't look very nice when boldfaced
%% This is a hack to use Helvetica instead
%% Usage: \textbf{\forbold some stuff}
%\newcommand{\forbold}{\fontspec{Helvetica}}
% \newcommand{\forbold}{} % if you want no special boldface
%%%%%%%%%%%%%%%%%%%%%%%%
% Usual LaTeX Packages %
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{unicode-math}
\setmathfont[math-style=upright]{Neo Euler}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{mathrsfs} % For Weinberg-esque letters
\usepackage{cancel} % For "SUSY-breaking" symbol
\usepackage{slashed} % for slashed characters in math mode
\usepackage{bbm} % for \mathbbm{1} (unit matrix)
\usepackage{amsthm} % For theorem environment
\usepackage{multirow} % For multi row cells in table
\usepackage{arydshln} % For dashed lines in arrays and tables
%\usepackage{tikzfeynman} % For Feynman diagrams
\usepackage{wasysym}
\usepackage{pifont}
\usepackage{ifsym}
%\usepackage{bbding}
% \usepackage{subfig} % for sub figures
% \usepackage{young} % For Young Tableaux
% \usepackage{xspace} % For spacing after commands
% \usepackage{wrapfig} % for Text wrap around figures
% \usepackage{framed}
%\graphicspath{{images/}} % Put all images in this directory. Avoids clutter.
%\usetikzlibrary{backgrounds}
%\usetikzlibrary{mindmap,trees} % For mind map
% http://www.texample.net/tikz/examples/computer-science-mindmap/
%\setbeamertemplate{background canvas}{\includegraphics [width=\paperwidth]{blackboard_bk.pdf}}
%==================%
\setbeamercolor{normal text}{fg=white}
\setbeamercolor{alerted text}{fg=red!80}
\setbeamercolor{structure}{fg=yellow!80}
\setbeamercolor{frametitle}{fg=green}
\setbeamercolor{title}{fg=white}
\setbeamertemplate{blocks}[shadow=false]
\setbeamercolor{block body}{fg=normal text.bg!90!black}
\setbeamercolor{block body example}{bg=normal text.bg!90!black}
\begin{document}
\begin{frame}{Test num\'ero 2}
\begin{block}{Un bloc normal}
Texte du block
\end{block}
\begin{alertblock}{Un bloc tr\`es alerte}
Texte du block
\end{alertblock}
\begin{exampleblock}{Un bloc exemplaire}
Exemple de block
\end{exampleblock}
\end{frame}
\end{document}
Best Answer
You can use the
tcolorbox
package:And adding the
beamer
skin:In a comment it has been requested to reduce the separation between title and contents; this can be done using
middle
andboxsep
; I also set the frame color to white and usedborderline
to produce the frame:A new request in a comment is to be able to add an eventual annotation to the environments (in a fashion similar to the optional argument of the structures defined with
\newtheorem
usingamsthm
orntheorem
). In this case, I think is better to use a style and\newtcbtheorem
:Notice the special way in which each theorem environment is invoked using three mandatory arguments: the first one for the name used to define the structure; the second one for the eventual annotation and the third one for a label for eventual cross-references. Since they are mandatory arguments, you have to use them always, even if empty, so
and not just