我想根据我的框架是否有标题来更改背景画布。这是我使用的表单(etoolbox):
\setbeamertemplate{background canvas}{
\ifnumequal{\c@framenumber}{1}{%
% First frame
}{%
\ifnumequal{\c@framenumber}{\inserttotalframenumber}{
% Last frame
}{%
%\if{\frametitle}{empty}{
% Empty frames
}{%
% Other frames
}%
}%
}
提前致谢。
答案1
您可以使用条件\ifx
来测试\insertframetitle
它是否为空并采取相应措施,一个简单的示例是在带有标题的框架中添加带有“B”的图像,并在带有标题的框架中添加带有“A”的图像:
\documentclass{beamer}
\usepackage{tikz}
\makeatletter
\setbeamertemplate{background canvas}{%
\ifx\insertframetitle\@empty
\tikz[remember picture,overlay]
\node[opacity=0.2] at (current page.center)
{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}};
\else
\tikz[remember picture,overlay]
\node[opacity=0.2] at (current page.center)
{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}};
\fi%
}
\makeatother
\begin{document}
\begin{frame}
\frametitle{A frame with a title}
test
\end{frame}
\begin{frame}
test
\end{frame}
\end{document}