Beamer 背景由变量定义

Beamer 背景由变量定义

过去几天我一直在尝试创建一个新的 Beamer 自定义样式。我已设法在样式(硬编码)的标题页背景中添加图像,但我想在指定该图像的文档中添加一个变量选项。但我尝试时失败了。

Style document 
\mode<presentation>

% Requirement
\RequirePackage{tikz}
\RequirePackage{graphicx}
\RequirePackage{fontspec}
\setmainfont{Calibri}

\AtBeginDocument{\setbeamertemplate{logo}{}}

\newcommand{\frontimage}{\includegraphics[width=\the\paperwidth, keepaspectratio]{Frontimage.JPG}} %my title page image hardcoded
\newcommand{\secimage}{\includegraphics[width=\the\paperwidth, keepaspectratio]{secimage.JPG}} %my section page image hardcoded
\useinnertheme{mytheme}
\useoutertheme{mytheme}
\usecolortheme{mytheme}

\defbeamertemplate*{background}{mytheme}{%
\begin{tikzpicture}
     \ifnum\thepage>1\relax%
          %if base frame
          \fill[white,opacity=1] (0,0) rectangle(\the\paperwidth,\the\paperheight);
     \else
          %if title page
          \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
          \node[anchor=south west,inner sep=0] (image) at (0,0) {\frontimage};
      \fi
\end{tikzpicture}
}
\mode<all>

Example Document
\documentclass[aspectratio=169]{beamer}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\title{Boring Title}

 \usetheme{mytheme}

 \begin{document}

 \begin{frame}
    \titlepage
 \end{frame}

 \section{Introduction}
    \sectionframe
  \begin{frame}
    \lipsum[1]
  \end{frame}
\end{document}

希望 MWE 能发挥作用

答案1

一种方法是将文件名作为可选参数传递给主题:

\documentclass[aspectratio=169]{beamer}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\title{Boring Title}

\usepackage{filecontents} % <- just for creating this example
\begin{filecontents*}{beamerthememytheme.sty}
\mode<presentation>

% Requirement
\RequirePackage{tikz}
%\RequirePackage{graphicx}
%\RequirePackage{fontspec}
%\setmainfont{Calibri}

%\AtBeginDocument{\setbeamertemplate{logo}{}}

\DeclareOptionBeamer{myimage}{\def\beamer@mytheme@myimage{#1}}
\ExecuteOptionsBeamer{myimage=example-image}
\ProcessOptionsBeamer


\newcommand{\frontimage}{\includegraphics[width=\paperwidth, keepaspectratio]{\beamer@mytheme@myimage}} %my title page image hardcoded
%\useinnertheme{mytheme}
%\useoutertheme{mytheme}
%\usecolortheme{mytheme}

\defbeamertemplate*{background}{mytheme}{%
\begin{tikzpicture}
     \ifnum\thepage>1\relax%
          %if base frame
          \fill[white,opacity=1] (0,0) rectangle(\the\paperwidth,\the\paperheight);
     \else
          %if title page
          \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
          \node[anchor=south west,inner sep=0] (image) at (0,0) {\frontimage};
      \fi
\end{tikzpicture}
}
\mode<all>
\end{filecontents*}

\usetheme[
    myimage=example-image-duck
]{mytheme}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Introduction}
%  \sectionframe
\begin{frame}
  \lipsum[1]
\end{frame}
\end{document}

相关内容