第一次尝试

第一次尝试

我正在使用自定义部分幻灯片创建自己的 Beamer 主题。理想情况下,我希望命令

\frame{\sectionpage}

有一个额外的可选参数,用于指定部分页面的颜色。

\frame{\sectionpage[yellow]}
\frame{\sectionpage[grey]}

我目前实现了自定义部分页面,如下所示,

\setbeamertemplate{section page}{
  \begin{tikzpicture}[remember picture, overlay]
    \node at (current page.center) {
      \pgfuseimage{gray_divider}
    };
  \end{tikzpicture}
  \textbf{\insertsectionhead}
}

第一次尝试

我找到了一种适用于一种颜色的解决方案。在 Beamer 内部主题类中,我定义以下内容,

文档.tex

\documentclass[10pt]{beamer}
\usepackage{bookmark}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage[english]{babel}
\usepackage{longtable,booktabs}
\usepackage{graphicx}
\usepackage{beamerthemeBeamerSome}

\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}


% Reduce line spacing before and after knitr chunk.
\renewenvironment{knitrout}{\setlength{\topsep}{0mm}}{}

\begin{document}

% This works.
\section*{Introduction}
\frame{\sectionpage[gray]}

% This fails.
\section*{Introduction}
\frame{\sectionpage[yellow]}

% This fails too.
\section*{Introduction}
\frame{\sectionpage}

\end{document}

beamerthemeBeamerSome.sty

\ProvidesPackage{beamerouterthemeinfolinesSome}
\mode<presentation>

% Import of standard packages
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{bookmark}
\usepackage{etoolbox}

% Set fonts to Arial
\usepackage[no-math]{fontspec}
\setmainfont{Arial}
\setsansfont{Arial}

% Implement Logo (logo should be located in the folder with this .sty file)
\pgfdeclareimage[width=\paperwidth]{titlepage}{2015_title_page.pdf}

% Color Definitions
\definecolor{gray}{RGB}{128,128,128}
\definecolor{darkgray}{RGB}{64,64,64}
\definecolor{yellow}{RGB}{255,210,0}

\usecolortheme[RGB={255,210,0}]{structure}

\providebool{SHOW_LINE_IN_FOOTER}
\providebool{SECTION_DIVIDER_YELLOW}
\boolfalse{SHOW_LINE_IN_FOOTER}
\boolfalse{SECTION_DIVIDER_YELLOW}

\newif\ifbeamer@secheader
\beamer@secheaderfalse

\DeclareOptionBeamer{secheader}{\beamer@secheadertrue}
\ProcessOptionsBeamer

\useinnertheme{Some}
\useoutertheme{infolinesSome}

\setbeamerfont{title}{size=\fontsize{15}{17}\bfseries}
\setbeamerfont{subtitle}{size=\fontsize{15}{17}\bfseries}
\setbeamerfont{date}{size =\fontsize{10.5}{11}}

\setbeamertemplate{title page}{
    \begin{tikzpicture}[remember picture, overlay]
        \node at (current page.center) {
      \pgfuseimage{titlepage}
        };
    \node [xshift = -0.2675\paperwidth, yshift = 0.1175\paperheight,
      color = darkgray, above right] at (current page.center) {
       \usebeamerfont{title}\inserttitle
    };
        \node [xshift = -0.2675\paperwidth, yshift = 0.06\paperheight,
      color = darkgray, above right] at (current page.center) {
        \usebeamerfont{subtitle}\insertsubtitle
    };
        \node [xshift = -0.2675\paperwidth, yshift = 0.037\paperheight,
      color = darkgray, below right] at (current page.center) {
        \usebeamerfont{date}\insertdate
    };
    \end{tikzpicture}
}{}

\setbeamersize{text margin left=1em,text margin right=1em}

\mode<all>

beamerinnerthemeSome.sty

\ProvidesPackage{beamerinnerthemeSome}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{xparse}

\ProcessOptionsBeamer

\mode<presentation>

\usesubitemizeitemtemplate{%
    \tiny\raise1.5pt\hbox{\color{beamerstructure}$\blacktriangleright$}%
}
\usesubsubitemizeitemtemplate{%
    \tiny\raise1.5pt\hbox{\color{beamerstructure}$\blacktriangleright$}%
}

\setbeamertemplate{items}[triangle]
\setbeamertemplate{section in toc}{
    {\color{yellow} $\blacktriangleright$} {\color{gray} \inserttocsection}
}
\setbeamertemplate{subsection in toc}{
  \hspace*{\itemindent} {\color{yellow} \tiny $\blacktriangleright$}
  {\color{gray} \tiny \inserttocsubsection} \par
}

\pgfdeclareimage[width=\paperwidth]{gray_divider}{gray_divider.pdf}
\pgfdeclareimage[width=\paperwidth]{yellow_divider}{yellow_divider.pdf}

\setbeamertemplate{section page}{
  \global\boolfalse{SHOW_LINE_IN_FOOTER}
  \begin{tikzpicture}[remember picture, overlay]
    \node at (current page.center) {
      \pgfuseimage{gray_divider}
    };
  \end{tikzpicture}

  % Code from my frametitle.
  \vskip4pt
  % Code from beamerouterthemedefault.sty
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \strut\insertsectionhead\strut%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
}

beamerouterthemeinfolinesSome.sty

\ProvidesPackage{beamerouterthemeinfolinesSome}
\usepackage{etoolbox}

\mode<presentation>

\setbeamercolor*{author in head/foot}{parent=palette tertiary}
\setbeamercolor*{title in head/foot}{parent=palette secondary}
\setbeamercolor*{footer info}{parent=palette primary}

\setbeamercolor*{section in head/foot}{parent=palette tertiary}
\setbeamercolor*{subsection in head/foot}{parent=palette primary}

\setbeamercolor{normal text}{fg=darkgray}
\setbeamercolor{palette primary}{fg=darkgray,bg=white}
\setbeamercolor{palette secondary}{fg=white,bg=darkgray}
\setbeamercolor*{palette tertiary}{fg=darkgray, bg=white}
\setbeamercolor{normal text}{fg=darkgray}
\setbeamercolor{section number projected}{fg=white,bg=darkgray}

\setbeamertemplate{frametitle}
{
    \vskip4pt
    \color{darkgray}
    \textbf{\insertframetitle}
    %\par
    %\vskip5pt

  \color{yellow}
  \centering
  \rule{0.94\paperwidth}{0.9pt}
}

\setbeamertemplate{footline}
{
  \leavevmode
  \centering

  \ifbool{SHOW_LINE_IN_FOOTER}{%
    \rule{0.94\paperwidth}{0.2pt}}{\global\booltrue{SHOW_LINE_IN_FOOTER}}
  \vskip5pt
  \hbox{
      \begin{beamercolorbox}[wd=.02\paperwidth,ht=0.0ex,dp=3ex,left]{footer info}%
       % dummy box
      \end{beamercolorbox}%

      \begin{beamercolorbox}[wd=.1\paperwidth,ht=4ex,dp=1ex,left]{footer info}%
        \usebeamerfont{author in head/foot}
         Page \insertframenumber{}
      \end{beamercolorbox}%

      \begin{beamercolorbox}[wd=.2\paperwidth,ht=4ex,dp=1ex,center]{footer info}%
        \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
      \end{beamercolorbox}%

      \begin{beamercolorbox}[wd=.5\paperwidth,ht=4ex,dp=1ex,left]{footer info}%
        \usebeamerfont{date in head/foot}\insertshorttitle
      \end{beamercolorbox}

      \begin{beamercolorbox}[wd=.13\paperwidth,ht=4ex,dp=3ex,right]{footer info}%
    \includegraphics[height=0.5cm]{Logo_New.pdf}
      \end{beamercolorbox}

      \begin{beamercolorbox}[wd=.03\paperwidth,ht=0.0ex,dp=3ex,left]{footer info}%
       % dummy box
      \end{beamercolorbox}%
  }
  \vskip2pt
}

\makeatletter
\defbeamertemplate{note page}{plain2}
{
  \vskip2.25em
  \nointerlineskip
  \begin{minipage}{0.95\textwidth} % this is an addition
  \insertnote
  \end{minipage}               % this is an addition
}
\makeatother
\setbeamertemplate{note page}[plain2]

\mode
<all>

错误

我添加了\tracingall调查问题的内容,并在日志文件中发现以下内容,

\@writefile #1#2->
#1<-nav
#2<-\headcommand {\slideentry {7}{0}{60}{60/60}{}{0}}
{blank space  }

\@writefile #1#2->
#1<-nav
#2<-\headcommand {\beamer@framepages {60}{60}}
{blank space  }

\HyPL@Entry #1->\expandafter \gdef \expandafter \HyPL@Labels \expandafter {\HyP
L@Labels #1}
)
Runaway argument?
{60<< 
! File ended while scanning use of \HyPL@Entry.
<inserted text> 

我不知道这个 HyPL 来自哪里。

更新

我猜到问题出在哪里了。显然,文件名中包含的下划线导致了这个问题。这段代码有效,

\pgfdeclareimage[width=\paperwidth]{yellowdivider}{gray_divider.pdf}
\pgfdeclareimage[width=\paperwidth]{graydivider}{gray_divider.pdf}

\setbeamertemplate{section page}{
  \global\boolfalse{SHOW_LINE_IN_FOOTER}
\ifbool{DIVIDER_IS_YELLOW}{%
    \begin{tikzpicture}[remember picture, overlay]
      \node at (current page.center) {
        \pgfuseimage{yellowdivider}
      };
    \end{tikzpicture}}{%
    \begin{tikzpicture}[remember picture, overlay]
      \node at (current page.center) {
        \pgfuseimage{graydivider}
      };
    \end{tikzpicture}}

  \global\booltrue{DIVIDER_IS_YELLOW}%
  % Code from beamerouterthemedefault.sty
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    %\if@tempswa\else\csname beamer@fte#1\endcsname\fi%
    \strut\insertframetitle\strut\par%
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
  \textbf{\insertsectionhead}
}

如果我在第一个 pgfdeclare 中替换文件名,则一切都会出错。因此,这似乎更像是 pgfdeclare 中的一个问题。

非常欢迎任何关于如何解决此问题的建议。

答案1

我按如下方式解决了这个问题,

内部主题文件包含以下代码,

 \setbeamertemplate{section page}{
   \global\boolfalse{SHOW_LINE_IN_FOOTER}
   \ifbool{DIVIDER_IS_YELLOW}{%
     \begin{tikzpicture}[remember picture, overlay]
       \node at (current page.center) {
         \includegraphics[width=\paperwidth]{yellow_divider.pdf}
       };
     \end{tikzpicture}}{%
     \begin{tikzpicture}[remember picture, overlay]
       \node at (current page.center) {
         \includegraphics[width=\paperwidth]{gray_divider.pdf}
       };
     \end{tikzpicture}}

   \global\booltrue{DIVIDER_IS_YELLOW}%
   % Code from beamerouterthemedefault.sty
   \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
   \@tempdima=\textwidth%
   \advance\@tempdima by\beamer@leftmargin%
   \advance\@tempdima by\beamer@rightmargin%
   \begin{beamercolorbox}[sep=0.3cm,wd=\the\@tempdima]{frametitle}
     \usebeamerfont{frametitle}%
     \vbox{}\vskip-1ex%
     %\if@tempswa\else\csname beamer@fte#1\endcsname\fi%
     \strut\insertframetitle\strut\par%
     {%
       \ifx\insertframesubtitle\@empty%
       \else%
       {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
       \fi
     }%
     \vskip-1ex%
     \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
   \end{beamercolorbox}%
   \textbf{\insertsectionhead}
 }

我的结论是ifbool,并且pgfdeclare玩得不好。

相关内容