带有 keyval 定义的 beamerposter 自定义样式

带有 keyval 定义的 beamerposter 自定义样式

我正在根据部门规范创建一种 beamerposter 样式。我想创建一个主题,其中块的定义可以根据主题调用中的关键字而变化。我试图用 MWE 解释自定义样式的工作原理如下

\ProvidesPackage{beamerthemeMYposter} % this style was created by David Vilar
% Define boolean options
% -----------------
\newif\if@shadowbox
\DeclareOption{shadowbox}{\@shadowboxtrue}
\DeclareOption*{\PackageWarning{beamerthemeMYposter}{Unknown option `\CurrentOption'}}
% process options
% ------------
\ProcessOptions
\mode<presentation>
\usepackage{tikz}       % for drawing the nice rounded boxes 
\usetikzlibrary{arrows,backgrounds}
\newcommand{\makeruleinbox}{{\usebeamercolor[bg]{block alerted title}\centering\hspace*{-0.7cm}\rule{\inboxrule}{0.5cm}}}
\usepackage{ragged2e} 
\newlength{\inboxwd}
\newlength{\iinboxwd}
\newlength{\inboxrule}
\makeatletter  
\makeatother
\usepackage{xcolor}

% Block definition
\setbeamercolor*{block body}{fg=blue,bg=white}
\setbeamerfont{block title}{size=\large,series=\bf}
% conditional block body definition
\if@shadowbox
\setbeamercolor*{block title}{bg=white,fg=red}
\setbeamercolor*{block body}{fg=blue, bg=white}
\setbeamerfont{block title}{size=\large,series=\bf}
\setbeamertemplate{block begin}
{
  \par\vskip\medskipamount
  \begin{beamercolorbox}[colsep*=.5ex,dp={2ex},center]{block title}
    \vskip-0.25cm
    \usebeamerfont{block title}\large\insertblocktitle
    \begin{flushleft}
      \vskip-1cm
      \begin{tikzpicture}[remember picture,overlay]
        \shade [inner color=blue,outer color=white]
        (0,0) rectangle (\textwidth,0.3cm);
      \end{tikzpicture}
    \end{flushleft}
  \end{beamercolorbox}
  {\parskip0pt\par}
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}
  \usebeamerfont{block body}
  \vskip-0.5cm
  \begin{beamercolorbox}[colsep*=.5ex,vmode]{block body}
    \justifying
  }

  \setbeamertemplate{block end}
  {
  \end{beamercolorbox}
  \vskip\smallskipamount
  }
\else
\setbeamercolor*{block title}{bg=blue,fg=white}
\setbeamertemplate{block begin}{
\vskip.75ex
\begin{beamercolorbox}[leftskip=1cm,colsep*=.75ex]{block title}%
\usebeamerfont*{block title}\insertblocktitle
\end{beamercolorbox}%
{\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
\usebeamerfont{block body}%
\begin{beamercolorbox}[colsep*=.75ex,sep=.75ex,vmode]{block body}%
\ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}
\setbeamertemplate{block end}{
\end{beamercolorbox}
}
\fi

\mode<all>

然后在文档中我尝试这样调用

\documentclass[final]{beamer}
\mode<presentation> {
\usepackage[size=a0,orientation=landscape,debug]{beamerposter}  % e.g. custom size poster
\usetheme[shadowbox]{MYposter}
}
\begin{document}
\begin{frame}{} 
\begin{block}{trial}
\end{block}
\end{frame}
\end{document}

如果您尝试这个 MWE,您会发现没有办法考虑 shadowbox 选项。我必须承认这是我第一次尝试在包创建中使用条件关键字。欢迎提出任何建议

答案1

从中删除\makeatletter命令:\makeatotherbeamerthemeMYposter.sty

\ProvidesPackage{beamerthemeMYposter} % this style was created by David Vilar
% Define boolean options
% -----------------
\newif\if@shadowbox
\DeclareOption{shadowbox}{\@shadowboxtrue}
\DeclareOption*{\PackageWarning{beamerthemeMYposter}{Unknown option `\CurrentOption'}}
% process options
% ------------
\ProcessOptions\relax
\mode<presentation>
\usepackage{tikz}       % for drawing the nice rounded boxes 
\usetikzlibrary{arrows,backgrounds}
\newcommand{\makeruleinbox}{{\usebeamercolor[bg]{block alerted title}\centering\hspace*{-0.7cm}\rule{\inboxrule}{0.5cm}}}
\usepackage{ragged2e} 
\newlength{\inboxwd}
\newlength{\iinboxwd}
\newlength{\inboxrule}

\usepackage{xcolor}

% Block definition
\setbeamercolor*{block body}{fg=blue,bg=white}
\setbeamerfont{block title}{size=\large,series=\bf}
% conditional block body definition
\if@shadowbox
\setbeamercolor*{block title}{bg=white,fg=red}
\setbeamercolor*{block body}{fg=blue, bg=white}
\setbeamerfont{block title}{size=\large,series=\bf}
\setbeamertemplate{block begin}
{
  \par\vskip\medskipamount
  \begin{beamercolorbox}[colsep*=.5ex,dp={2ex},center]{block title}
    \vskip-0.25cm
    \usebeamerfont{block title}\large\insertblocktitle
    \begin{flushleft}
      \vskip-1cm
      \begin{tikzpicture}[remember picture,overlay]
        \shade [inner color=blue,outer color=white]
        (0,0) rectangle (\textwidth,0.3cm);
      \end{tikzpicture}
    \end{flushleft}
  \end{beamercolorbox}
  {\parskip0pt\par}
  \ifbeamercolorempty[bg]{block title}
  {}
  {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}
  \usebeamerfont{block body}
  \vskip-0.5cm
  \begin{beamercolorbox}[colsep*=.5ex,vmode]{block body}
    \justifying
  }

  \setbeamertemplate{block end}
  {
  \end{beamercolorbox}
  \vskip\smallskipamount
  }
\else
\setbeamercolor*{block title}{bg=blue,fg=white}
\setbeamertemplate{block begin}{
\vskip.75ex
\begin{beamercolorbox}[leftskip=1cm,colsep*=.75ex]{block title}%
\usebeamerfont*{block title}\insertblocktitle
\end{beamercolorbox}%
{\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
\usebeamerfont{block body}%
\begin{beamercolorbox}[colsep*=.75ex,sep=.75ex,vmode]{block body}%
\ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}
\setbeamertemplate{block end}{
\end{beamercolorbox}
}
\fi

\mode<all>

使用时\ProcessOptions,最好\relax在末尾使用 来停止搜索星星。

相关内容