问题

问题

问题

我正在为我的大学制作一个模板。我已经能够创建大部分内容,但我无法尝试创建一个名为的框架titlepage。具体来说,在这个框架中,我希望用户能够替换他们选择的图像的部分背景。如下所示

在此处输入图片描述

理想情况下我想要以下语法

\begin{frame}{titlepage, img=example-image-a, pos=0.6}
   content here
\end{frame}

或者

\begin{titlepage}{img=example-image-a, pos=0.6}
   content here
\end{titlepage}

在...的帮助下将图像与另一幅图像的部分叠加从头创建一个简单的大学 Beamer 模板我能够得出底部的 MWE。然而,我有几个问题

  • 首页图片删除了幻灯片上的所有文字
  • 我只希望用户能够在我选择的首页上插入图像
  • 我无法创建上面描述的关键语法

uit-背景-标题页.png

在此处输入图片描述

代码

\documentclass[aspectratio=169]{beamer}
% \usetheme{uit}
\usepackage[english]{babel} % Main language to the right ->
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\UiTtitlepageBackground}{%
  \expandafter\includegraphics\expandafter[%
    width=\paperwidth,
    height=\paperheight]{uit-background-titlepage.png}%
}

\setbeamertemplate{background canvas}{
}

\usepackage{etoolbox}
\BeforeBeginEnvironment{frame}{%
    \setbeamertemplate{background}{}%
}

\makeatletter
\define@key{beamerframe}{titlepage}[true]{%
    \setbeamertemplate{background}{%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
        \UiTtitlepageBackground\hfil}\vfil}%
    }%
}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\title{There Is No Largest Prime Number and way to to to much info}
\subtitle{subtitle na na na na na na na na na na na na na na na batman}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{[email protected]}}

\makeatletter
\AtBeginDocument{
  \newlength\beamerleftmargin
  \setlength\beamerleftmargin{\Gm@lmargin}
}
\makeatother

\newcommand{\titleimage}[2][0]{%
  \pgfmathsetmacro\xpos{max(min(#1,1),0)*0.5855}
  \begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
    \node (X) {%
        \hspace*{-\beamerleftmargin}%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
        \UiTtitlepageBackground\hfil}\vfil}%
      };
    \begin{scope}[x={(X.south east)},y={(X.north west)}]
      \begin{scope}
        \clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
      \path let \p1=(X.north east) in (\xpos,0)
        node{\includegraphics[width=\x1,height=\y1]{#2}};
    \end{scope}
  \end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}[titlepage]
  \titleimage[0.55]{example-image-a}
  \titlepage
\end{frame}

\begin{frame}
  \titleimage[0.6]{example-image-c}
  \begin{theorem}
    Hmmm
  \end{theorem}
  \begin{example}
    \begin{enumerate}
      \item hello
      \item hi
      \item woah
    \end{enumerate}
  \end{example}
\end{frame}

\end{document}

答案1

我认为我没有完全理解您遇到的所有问题,但其中一个问题似乎是将一组选项传递给模板titleimage。由于您使用的是 pgf,所以这很容易。下面包含一个示例,一旦我理解了问题的所有方面,就可以对其进行完善。模板现在正在解析 pgf 键并使用它们。例如,如果您说

\begin{frame}[t,titleimage={file=example-image-a}]
\frametitle{Something}
  \begin{theorem}
    Hmmm
  \end{theorem}
  \begin{example}
    \begin{enumerate}
      \item hello
      \item hi
      \item woah
    \end{enumerate}
  \end{example}
\end{frame}

你得到

在此处输入图片描述

\begin{frame}[titleimage={file=example-image-duck,pos=0.6}]
\frametitle{Something else}
\begin{itemize}
 \item blub
 \item quack
 \item pft
 \item meow
\end{itemize}
\end{frame}

在此处输入图片描述

重要的是,我们pos在这里添加了一个可选键。如果您不指定它,它将假定某个默认值。至关重要的是,您可以根据需要添加任意数量的此类键,并且您可以随时升级模板以允许添加其他键,而不会失去向后兼容性。

以下是完整的代码。

\documentclass[aspectratio=169]{beamer}
% \usetheme{uit}
\usepackage[english]{babel} % Main language to the right ->
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\UiTtitlepageBackground}{%
  \expandafter\includegraphics\expandafter[%
    width=\paperwidth,
    height=\paperheight]{uit-background-titlepage.png}%
}

\setbeamertemplate{background canvas}{
}

\usepackage{etoolbox}
\BeforeBeginEnvironment{frame}{%
    \setbeamertemplate{background}{}%
}

\makeatletter
\define@key{beamerframe}{titlepage}[true]{%
    \setbeamertemplate{background}{%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
        \UiTtitlepageBackground\hfil}\vfil}%
    }%
}


\define@key{beamerframe}{titleimage}[]{%
    \Titleimage{#1}%
}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\title{There Is No Largest Prime Number and way to to to much info}
\subtitle{subtitle na na na na na na na na na na na na na na na batman}
\date[ISPN '80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{[email protected]}}

\makeatletter
\AtBeginDocument{
  \newlength\beamerleftmargin
  \setlength\beamerleftmargin{\Gm@lmargin}
}
\makeatother
\pgfkeys{/title image/.cd,pos/.initial=0,file/.initial=example-image-duck}
\newcommand{\Titleimage}[1]{%
\setbeamertemplate{background}{%
  \pgfkeys{title image/.cd,#1}% 
  \pgfmathsetmacro\xpos{max(min(\pgfkeysvalueof{/title image/pos},1),0)*0.5855}%
  \begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
    \node (X) {%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
        \UiTtitlepageBackground\hfil}\vfil}%
      };
    \begin{scope}[x={(X.south east)},y={(X.north west)}]
      \begin{scope}
        \clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
      \path let \p1=(X.north east) in (\xpos,0)
        node{\includegraphics[width=\x1,height=\y1]{\pgfkeysvalueof{/title
        image/file}}};
    \end{scope}
  \end{scope}
\end{tikzpicture}}
}
\newcommand{\titleimage}[2][0]{%
  \pgfmathsetmacro\xpos{max(min(#1,1),0)*0.5855}
  \begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
    \node (X) {%
        \hspace*{-\beamerleftmargin}%
        \vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil%
        \UiTtitlepageBackground\hfil}\vfil}%
      };
    \begin{scope}[x={(X.south east)},y={(X.north west)}]
      \begin{scope}
        \clip (0.5855,0) -- (0.833,1) -| (1,0) -- cycle;
      \path let \p1=(X.north east) in (\xpos,0)
        node{\includegraphics[width=\x1,height=\y1]{#2}};
    \end{scope}
  \end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}[t,titleimage={file=example-image-a}]
\frametitle{Something}
  \begin{theorem}
    Hmmm
  \end{theorem}
  \begin{example}
    \begin{enumerate}
      \item hello
      \item hi
      \item woah
    \end{enumerate}
  \end{example}
\end{frame}

\begin{frame}[titleimage={file=example-image-duck,pos=0.6}]
\frametitle{Something else}
\begin{itemize}
 \item blub
 \item quack
 \item pft
 \item meow
\end{itemize}
\end{frame}

\end{document}

正如我所说的,它还没有简化,因为我强烈地感觉到我没有解决你提出的所有问题(但我无法理解它们,也因为我无法从语法和逻辑上理解例如“我只希望用户能够在我选择的首页上插入图像”。)

相关内容