自定义 Beamer 主题没有按我预期的那样安排东西

自定义 Beamer 主题没有按我预期的那样安排东西

我正在创建自己的 Beamer 主题(让我称之为神话主题在本线程中),目前正在制作标题页。首先,我将下面显示的代码放在 中,该代码由主beamerinnerthememytheme.sty加载。\useinnertheme{mytheme}beamerthememytheme.sty

% this is "beamerthememytheme.sty"
\mode<presentation>
% dependencies
\RequirePackage{tikz}
% load theme (outer and font themes are empty at the moment)
\useinnertheme{mytheme}
\useoutertheme{mytheme}
\usecolortheme{mytheme}
\usefonttheme{mytheme}
% settings
%% erase navigation symbols
\setbeamertemplate{navigation symbols}{}
%% use "goshikku-tai" (Japanese counterpart of Alphabetical sans-serif) as a default Japanese font
%% when pTeX engine, its derivatives or luatex-ja package is used.
\ifdefined\kanjifamilydefault
    \renewcommand\kanjifamilydefault{\gtdefault}
\else
    \relax %
\fi
\mode<all>
% --------------------
% this is "beamerinnerthememytheme.sty"
\mode<presentation>
\defbeamertemplate*{title page}{mytheme}[1][]{
    \begin{beamercolorbox}{title and subtitle}
        \begin{tikzpicture}
            \useasboundingbox (0, 0) rectangle (\the\columnwidth, \the\paperheight); % assign a bounding box
            \fill[titlepagesidecolumn] (-\beamer@leftmargin, 0) rectangle (-0.35*\beamer@leftmargin, \the\paperheight);
            \ifx\insertsubtitle\@empty
                \node[anchor=west, font=\Huge\bfseries] at (0, 0.575*\the\paperheight) {\inserttitle};
            \else
                \node[anchor=west, font=\Huge\bfseries] at (0, 0.625*\the\paperheight) {\inserttitle};
                \node[anchor=west] at (0, 0.55*\the\paperheight) {\insertsubtitle};
            \fi
        \end{tikzpicture}
    \end{beamercolorbox}
    \begin{beamercolorbox}{institute}
        \begin{tikzpicture}
            \node[anchor=west, font=\Large] at (0, 0.4*\the\paperheight) {\insertinstitute};
        \end{tikzpicture}
    \end{beamercolorbox}
    \begin{beamercolorbox}{author}
        \begin{tikzpicture}
            \node[anchor=west, font=\LARGE] at (0, 0.325*\the\paperheight) {\insertauthor};
        \end{tikzpicture}
    \end{beamercolorbox}
    \begin{beamercolorbox}{date}
        \begin{tikzpicture}
            \node[anchor=east, font=\small] at (\the\columnwidth, 0.15*\the\paperheight) {\insertdate};
        \end{tikzpicture}
    \end{beamercolorbox}%
}
\mode<all>   
% --------------------
% this is "beamercolorthememytheme.sty"
\mode<presentation>
\definecolor{titlepagesidecolumn}{HTML}{2792C3}
\mode<all>
% --------------------
% this is "mwe.tex"
\documentclass[aspectratio=1610]{beamer}
\usetheme{mytheme}
\title{Enter the title here}
\subtitle{Enter the subtitle here}
\institute{Enter the author's institute here}
\author{Enter the author's name here}
\date{Enter the date here}
\begin{document}
\begin{frame}
    \titlepage
\end{frame}
\end{document}

结果如下图所示。

输出

我对这段代码有两个问题:

  1. institute并且authordate出现,并且
  2. \the\paperheight虽然蓝色条的垂直范围设置为从 0 到(是否有类似的东西text margin top?),但蓝色条和框架上边缘之间有一个白色空间。

我知道将所有元素放在一个beamercolorbox环境中会产生针对第一个问题的所需输出。

输出2

但是,我想将它们分开,beamercolorbox以便可以通过 分别在文档序言中更改每个组件的外观\setbeamer***

我应该如何修改代码来解决这些问题?

答案1

我建议您不要使用\paperwidth和,而是使用节点系列并根据这些模式放置所有内容(这意味着您必须使用每个节点的键,并且文档需要运行两次才能使元素到达其最终位置)。\paperheighcurrent page.remember picture,overlaytikzpicture

完整示例:

\documentclass{beamer}
\usepackage{tikz}

\colorlet{titlepagesidecolumn}{cyan}

\newlength\TitleLeftMargin
\setlength\TitleLeftMargin{20pt}

\makeatletter
\defbeamertemplate*{title page}{mytheme}[1][]{
    \leavevmode\begin{beamercolorbox}{title and subtitle}
        \begin{tikzpicture}[remember picture,overlay]
            \fill[titlepagesidecolumn] 
              (current page.north west) 
                rectangle 
              ([xshift=.5\beamer@leftmargin]current page.south west); 
            \ifx\insertsubtitle\@empty\relax
                \node[anchor=west, font=\Huge\bfseries] 
                  at ([yshift=20pt,xshift=\TitleLeftMargin]current page.west) 
                  {\inserttitle};
            \else
                \node[anchor=west, font=\Huge\bfseries] 
                  at ([yshift=30pt,xshift=\TitleLeftMargin]current page.west) 
                  {\inserttitle};
                \node[anchor=north west] 
                  at ([yshift=20pt,xshift=\TitleLeftMargin]current page.west) 
                  {\insertsubtitle};
            \fi
        \end{tikzpicture}
    \end{beamercolorbox}%
    \begin{beamercolorbox}{institute}
        \begin{tikzpicture}[remember picture,overlay]
            \node[anchor=west, font=\Large] 
              at ([yshift=-30pt,xshift=\TitleLeftMargin]current page.west) 
              {\insertinstitute};
        \end{tikzpicture}
    \end{beamercolorbox}%
    \begin{beamercolorbox}{author}
        \begin{tikzpicture}[remember picture,overlay]
            \node[anchor=north west, font=\LARGE] 
              at ([yshift=-35pt,xshift=\TitleLeftMargin]current page.west) 
              {\insertauthor};
        \end{tikzpicture}
    \end{beamercolorbox}%
    \begin{beamercolorbox}{date}
        \begin{tikzpicture}[remember picture,overlay]
            \node[anchor=south, font=\small] 
              at ([yshift=50pt]current page.south) 
            {\insertdate};
        \end{tikzpicture}
    \end{beamercolorbox}%
}
\makeatother

\title{The title}
\subtitle{The subtitle}
\institute{The Institute}
\author{The author}
\date{\today}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\end{document}

结果:

在此处输入图片描述

相关内容