重置投影机标题时,符号“\setbox”出现“未定义控制序列”错误

重置投影机标题时,符号“\setbox”出现“未定义控制序列”错误

在我的 Beamer 演示文稿中,我希望有infolinesoutertheme 的页脚和treeoutertheme 的页眉,但在第一行显示副标题而不是标题。因此,我将其infolines作为 outertheme 并\setbeamertemplate[headline]进行复制beamerouterthemetree.sty。它可以工作并进行编译,但我不喜欢它给出以下错误:

ERROR: Undefined control sequence.

--- TeX said ---
\beamer@@tmpl@headline .../foot} \setbox \tempbox 
                                                  =\hbox {\insertsectionhead...
l.108 \begin{document}

--- HELP ---
TeX encountered an unknown command name. You probably misspelled the
name. If this message occurs when a LaTeX command is being processed,
the command is probably in the wrong place---for example, the error
can be produced by an \item command that's not inside a list-making
environment. The error can also be caused by a missing \documentclass
command.

这是我的(剥离/纯化)代码:

\documentclass{beamer}

\usepackage{ragged2e}
\usepackage{etoolbox}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,shapes}
\apptocmd{\enumerate}{\justifying}{}{}
\apptocmd{\itemize}{\justifying}{}{}
\addtobeamertemplate{block begin}{}{\justifying}

\usetheme{default}
\usecolortheme{beaver}
\useoutertheme{infolines}
\useinnertheme{default}
\setbeamertemplate{sections/subsections in toc}[square]
\setbeamercolor{titlelike}{bg=darkred,fg=gray!15!white}
\setbeamercolor{frametitle}{fg=darkred}
\setbeamercolor{item}{fg=darkred}
\setbeamercolor{author in head/foot}{bg=darkred,fg=gray!5!white}

\setbeamertemplate{headline}
{%
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
      \usebeamerfont{title in head/foot}\insertshortsubtitle
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
      \usebeamerfont{section in head/foot}
      \setbox\tempbox=\hbox{\insertsectionhead}%
      \ifdim\wd\tempbox>1pt%
        \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
        \hskip1pt%
      \fi%
      \insertsectionhead
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
      \usebeamerfont{subsection in head/foot}
      \setbox\tempbox=\hbox{\insertsubsectionhead}%
      \ifdim\wd\tempbox>1pt%
        \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
        \hskip1pt%
      \fi%
      \insertsubsectionhead
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
    \end{beamercolorbox}
}

\title{My (short) title}
\subtitle{Yet longer and not shortable subtitle}
\institute[SIN]{Long Long Long Long Long Long Institute Name}
\author[S. Name \and S. Name]{Name \textsc{Long} \and Name \textsc{Long}}
\justifying
\begin{document}

\frame[plain]{\titlepage}

\begin{frame}
  \frametitle{Plan}
  \tableofcontents[pausesections,subsectionstyle=shaded]
\end{frame}

\end{document}

答案1

您需要分配一个盒子,所以

\newsavebox{\tempbox}

如果你想使用 Beamer 的临时盒子寄存器,请这样做

\makeatletter
\setbeamertemplate{headline}
{%
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
      \usebeamerfont{title in head/foot}\insertshortsubtitle
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
      \usebeamerfont{section in head/foot}
      \sbox\beamer@tempbox{\insertsectionhead}%
      \ifdim\wd\beamer@tempbox>1pt
        \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
        \hskip1pt
      \fi
      \insertsectionhead
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
      \usebeamerfont{subsection in head/foot}
      \sbox\beamer@tempbox{\insertsubsectionhead}%
      \ifdim\wd\beamer@tempbox>1pt
        \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
        \hskip1pt
      \fi
      \insertsubsectionhead
    \end{beamercolorbox}
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
    \end{beamercolorbox}
}
\makeatother

请注意,我使用以下方法修复了代码

\sbox\beamer@tempbox{\insertsectionhead}%

这是正确的命令,因为它是“颜色感知的”,但\setbox\beamer@tempbox=\hbox{\insertsectionhead}事实并非如此。

因此,无论您选择哪种方法,请使用\sbox

相关内容