编辑:

编辑:

我正在尝试从现有示例中创建 Beamer 演示模板,但在“beamerinnertheme.sty 文件”中的以下代码行中遇到了问题:

\defbeamertemplate*{background}{Custom theme}{
  \begin{tikzpicture}
  \useasboundingbox (0,0) rectangle (\the\paperwidth,\the\paperheight);
  \ifnum\thepage>1\relax %not the title page
        \fill[color=\usebeamercolor[bg]{palette primary}] (0,8) rectangle (0.8,8.3);
        \fill[color=\usebeamercolor[bg]{palette secondary}] (0.9,8) rectangle (\the\paperwidth, 8.3);
  \else% Title page
        \fill[color=\usebeamercolor[bg]{palette primary}] (0,0) rectangle (\the\paperwidth,\the\paperheight);
        \path[fill stretch image =img/wave_blue_aqua_4c] (0,0) rectangle (\textwidth,3);
  \fi
  \end{tikzpicture}
}

我得到的错误结果如下:

! Use of \tikz@parabola doesn't match its definition.
\beamer@@tmpl@background ...sebeamercolor [bg]{pal
ette primary}] (0,0) recta...

我做错了什么?错误来自指定标题页背景填充的位置:

        \fill[color=\usebeamercolor[bg]{palette primary}] (0,0) rectangle (\the\paperwidth,\the\paperheight);

如果注释掉此行,错误就会消失。我尝试使用简单的数字代替和\paperwidth变量\paperheight,以及对矩形左下角使用不同的说明符(除 之外(0,0),但这些都无法解决问题。

这似乎是一个语法错误,但就我而言,我看不出这是怎么回事。

编辑:

这是一个简单的例子:

beamerinnerthememycustomtheme.sty

\mode<presentation>

\setbeamertemplate{items}[circle]
\setbeamertemplate{sections/subsections in toc}[circle]

\newenvironment{xplainframe}{\bgroup\setbeamertemplate{background}{}\begin{frame}[plain]}{\end{frame}\egroup}

\defbeamertemplate*{background}{mycustomtheme theme}{
  \begin{tikzpicture}
  \useasboundingbox (0,0) rectangle (\the\paperwidth,\the\paperheight);
  \ifnum\thepage>1\relax %not the title page
        \fill[color=\usebeamercolor[bg]{palette primary}] (0,8) rectangle (0.8,8.3);
        \fill[color=\usebeamercolor[bg]{palette secondary}] (0.9,8) rectangle (\the\paperwidth, 8.3);
  \else% Title page
        \fill[color=\usebeamercolor[bg]{palette primary}] (0,2.5) rectangle (\the\paperwidth,\the\paperheight);
  \fi
  \end{tikzpicture}
}

\mode
<all>

beamerthememycustomtheme.sty

\DeclareOptionBeamer{compress}{\beamer@compresstrue}
\ProcessOptionsBeamer

\mode<presentation>

\useinnertheme{mycustomtheme}

\mode
<all>

example.tex

\documentclass{beamer}


\usetheme{mycustomtheme} 

\usepackage{tikz}

\author{Author}
\title{Presentation Title}
\institute{My University}
\date{\today}

\begin{document}
\frame{\maketitle}
\begin{frame}{Table of contents}
    \tableofcontents
\end{frame}

\section{Introduction}
\begin{frame}{First Slide}
\begin{itemize}
\item First item
\begin{itemize}
\item First sub item
\begin{itemize}
\item First sub sub item
\end{itemize}
\end{itemize}
\end{itemize}
\end{frame}


\end{document}

答案1

令人费解的错误是由于可选]参数中的\fill应该

\fill[color={\usebeamercolor[bg]{palette primary}}]

用括号保护]。然而,这不起作用,因为构造

\usebeamercolor[bg]{palette primary}

不会直接扩展为颜色名称,而是只有在经过包括赋值的一系列操作之后才会扩展为颜色名称。

一种解决方法是间接获取颜色:

\mode<presentation>

\setbeamertemplate{items}[circle]
\setbeamertemplate{sections/subsections in toc}[circle]

\newenvironment{xplainframe}
  {\bgroup\setbeamertemplate{background}{}\begin{frame}[plain]}
  {\end{frame}\egroup}

\AtBeginDocument{%
  \sbox0{\usebeamercolor[bg]{palette primary}\xglobal\colorlet{paletteprimary}{.}}%
  \sbox0{\usebeamercolor[bg]{palette secondary}\xglobal\colorlet{palettesecondary}{.}}%
}

\defbeamertemplate*{background}{mycustomtheme theme}{
  \begin{tikzpicture}
  \useasboundingbox (0,0) rectangle (\the\paperwidth,\the\paperheight);
  \ifnum\value{page}>1\relax %not the title page
        \fill[color=paletteprimary] (0,8) rectangle (0.8,8.3);
        \fill[color=palettesecondary] (0.9,8) rectangle (\the\paperwidth, 8.3);
  \else% Title page
        \fill[color=paletteprimary] (0,0) rectangle (\the\paperwidth,\the\paperheight);
  \fi
  \end{tikzpicture}
}

\mode
<all>

但是,如果我用这个修改过的主题文件编译示例文件,则不会得到任何输出,因为显然palette primarypalette secondary都指向白色。您需要定义自己的颜色版本。

请注意,最后\fill应该有(0,0),而不是(0,2.5)

相关内容