![Beamer:\usebackgroundtemplate + \only:问题重复的框架和索引偏移了 1](https://linux22.com/image/433641/Beamer%EF%BC%9A%5Cusebackgroundtemplate%20%2B%20%5Conly%EF%BC%9A%E9%97%AE%E9%A2%98%E9%87%8D%E5%A4%8D%E7%9A%84%E6%A1%86%E6%9E%B6%E5%92%8C%E7%B4%A2%E5%BC%95%E5%81%8F%E7%A7%BB%E4%BA%86%201.png)
我正在尝试将\only<1>{...}
图像放入 beamer 的背景幻灯片中。但是,我需要将+1
中的所有值都添加到 中\only
,即我需要写入\only<2>{...}
以在第一帧上显示图像。尽管不切实际,但问题是它还会将最后一张幻灯片复制 2 次,这会毫无理由地创建额外的、不必要的幻灯片...
有什么原因吗?我怎样才能恢复正常编号并删除最后一个不需要的帧?
谢谢!
梅威瑟:
\documentclass[table,aspectratio=169]{beamer}
\useoutertheme[footline=institutetitle,subsection=false]{miniframes}
\usecolortheme{beaver}
\begin{document}
{\usebackgroundtemplate{%
% Why do I need to add 1 to get the correct value for only, and how can I remove the last, doubled, slide?
\only<2>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}%
\only<3>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}}%
\only<4>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-c}}%
}
\begin{frame}[t]
\begin{itemize}
\item \onslide<1>{A}
\item \onslide<2>{B}
\item \onslide<3>{C (see that on the next slide there is an empty slide...)}
\end{itemize}
\end{frame}
}
\end{document}
-- 编辑 -- 给出的解决方案的问题此主题它会创建额外的页面而不是将所有幻灯片放在一页中......
\documentclass{beamer}
\useoutertheme[footline=institutetitle,subsection=false]{miniframes}
\usecolortheme{beaver}
\setbeamercolor{separation line}{use=structure,bg=darkred!80!black}
\begin{document}
\section{test}
{
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}}
\begin{frame}<1>[label=myframelabel]
\begin{itemize}
\item<+-> a
\item<+-> b
\item<+-> c
\item<+-> d
\item<+-> e
\end{itemize}
\end{frame}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-b}}
\againframe<2>{myframelabel}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-c}}
\againframe<3>{myframelabel}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}}
\againframe<4->{myframelabel}
}
\begin{frame}
Hello, I'm a new empty frame
\end{frame}
\end{document}
答案1
您在背景模板中用得太多了\only
。您可以简单地检索幻灯片编号并根据其值选择图形:
\documentclass[table,aspectratio=169]{beamer}
\useoutertheme[footline=institutetitle,subsection=false]{miniframes}
\usecolortheme{beaver}
\begin{document}
\ExplSyntaxOn
\usebackgroundtemplate{%
\tl_set:Nx \l_tmpa_tl {example-image-\int_to_alph:n{\insertslidenumber}}
\includegraphics[width=\paperwidth,height=\paperheight]{\l_tmpa_tl}}
\ExplSyntaxOff
\begin{frame}[t]
\begin{itemize}
\item \onslide<1>{A}
\item \onslide<2>{B}
\item \onslide<3>{C (see that on the next slide there is an empty slide...)}
\end{itemize}
\end{frame}
\end{document}
答案2
在 Ulrich 回答之后,我提出了这个代码来处理像 这样的范围<4-5>
,并对重复代码进行一些分解。所以我没有带来任何新想法,但我只是想提供它以供参考。我不确定这是否是一个很好的做法,可以newcommand
与ExplSyntax
... 混合使用,但它看起来真的很好,非常感谢!它还适用于 miniframes、页面...
\documentclass[table,aspectratio=169]{beamer}
\useoutertheme[footline=institutetitle,subsection=false]{miniframes}
\usecolortheme{beaver}
\ExplSyntaxOn
\newcommand{\addBackgroundOne}[2]{
\bool_if:nT {\int_compare_p:n{\insertslidenumber=#1}}{%
\includegraphics[width=\paperwidth,height=\paperheight]{#2}
}
}
\newcommand{\addBackgroundSlice}[3]{
\bool_if:nT {\int_compare_p:n{\insertslidenumber>=#1} && \int_compare_p:n{\insertslidenumber<=#2}}{%
\includegraphics[width=\paperwidth,height=\paperheight]{#3}
}
}
\ExplSyntaxOff
\begin{document}
{
\usebackgroundtemplate{%
\addBackgroundOne{1}{example-image-a}
\addBackgroundSlice{2}{3}{example-image-b}
\addBackgroundOne{4}{example-image-c}
}
\begin{frame}[t]
\begin{itemize}
\item A
\pause
\item B
\pause
\item B
\pause
\item C
\end{itemize}
\end{frame}
}
\end{document}