如何在 Beamer 中自定义块

如何在 Beamer 中自定义块

我想在 Beamer 中自定义块(alertblock)。我想要一个透明的块,带有红色框架,标题也是红色,如下图所示:

球门(圆角)

梅威瑟:

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

答案1

您可以使用tcolorbox包裹:

\documentclass{beamer}
\usepackage{tcolorbox}

\newtcolorbox{mybox}[1][Theorem:]{
colback=white,
colbacktitle=white,
coltitle=red!70!black,
colframe=red!70!black,
boxrule=1pt,
titlerule=0pt,
arc=15pt,
title={\strut#1}
}

\begin{document}

\begin{frame}
\begin{mybox}
test
\end{mybox}
\begin{mybox}[Proposition:]
test
\end{mybox}
\end{frame}

\end{document}

在此处输入图片描述

添加beamer皮肤:

\documentclass{beamer}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][Theorem:]{
beamer,
colback=white,
colbacktitle=white,
coltitle=red!70!black,
colframe=red!70!black,
boxrule=1pt,
titlerule=0pt,
arc=15pt,
title={\strut#1}
}

\begin{document}

\begin{frame}
\begin{mybox}
test
\end{mybox}
\begin{mybox}[Proposition:]
test
\end{mybox}
\end{frame}

\end{document}

在此处输入图片描述

在评论中,有人要求减少标题和内容之间的分离;这可以使用middle和来完成boxsep;我还将框架颜色设置为白色并用于borderline制作框架:

\documentclass{beamer}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][Theorem:]{
beamer,
colback=white,
colbacktitle=white,
coltitle=red!70!black,
colframe=white,
boxrule=1pt,
titlerule=0pt,
arc=15pt,
middle=0pt,
boxsep=0pt,
borderline={0.5pt}{0pt}{red},
title={\strut#1}
}

\begin{document}

\begin{frame}
\begin{mybox}
test
\end{mybox}
\begin{mybox}[Proposition:]
test
\end{mybox}
\end{frame}

\end{document}

在此处输入图片描述

评论中的新请求是能够向环境添加最终注释(以类似于\newtheorem使用amsthm或定义的结构的可选参数的方式ntheorem)。 在这种情况下,我认为最好使用样式和\newtcbtheorem

\documentclass{beamer} 
\usepackage{tcolorbox} 
\tcbuselibrary{skins,theorems}

\tcbset{
mybox/.style={
  beamer,
  colback=white,
  colbacktitle=white,
  coltitle=red!70!black,
  colframe=white,
  boxrule=1pt,
  titlerule=0pt,
  arc=15pt,
  middle=0pt,
  boxsep=0pt,
  borderline={0.5pt}{0pt}{red},
  theorem name,
  description delimiters=(),
  title={\strut#1}
  }
}
\newtcbtheorem{theo}{Theorem}{mybox}{thm}
\newtcbtheorem{prop}{Proposition}{mybox}{pro}

\begin{document}

\begin{frame}

\begin{theo}{}{testa}
test
\end{theo}
\begin{theo}{Fundamental theorem of algebra}{testb}
test
\end{theo}
\begin{prop}{}{testc}
test
\end{prop}
\begin{prop}{Some important proposition}{testc}
test
\end{prop}

\end{frame}

\end{document}

在此处输入图片描述

请注意,每个定理环境都使用三个强制参数来调用,这种方式非常特殊:第一个参数用于定义结构的名称;第二个参数用于最终注释;第三个参数用于最终交叉引用的标签。由于它们是强制参数,因此您必须始终使用它们,即使为空,因此

\begin{prop}{}{}
test
\end{prop}

不仅仅是

\begin{prop}
test
\end{prop}

答案2

使用/来自 dynblock 包的示例

\documentclass{ beamer }
\usepackage[shadow ,roundedcorners]{ dynblocks }
\usetheme{ Luebeck }
\begin{ document }
\begin{ frame }{ The frame title }
\begin{ columns }[T]
\begin{ column }{0.4\textwidth}
\begin{ dynblock }
\opaqueblock<1>[0.8\textwidth]{ hello this is a
\dynalert<2>{ dynamic block } with an
\alert<1 ,2>{ itemize } environment :
\begin{ itemize }
\item hello
\item hello again
\end{ itemize }
}
\invblock<2 ->
\end{ dynblock }
\end{ column }
7\begin{ column }{0.4\textwidth}
\begin{ dynblock }
\setalignment{ center }
\opaqueblock<2>{ hello this is another dynamic block }
\end{ dynblock }
\end{ column }
\end{ columns }
\end{ frame }
\end{ document }

相关内容