我想使用一张图片作为特定投影仪幻灯片的整页背景。我希望图片填满整个幻灯片,但保留其纵横比(与幻灯片的纵横比不同),图片在幻灯片上居中(水平和垂直)并精确放大到图片覆盖整个幻灯片的程度(因此可见部分会沿着图片相对较长的一侧被裁剪)。
换句话说,我想复制桌面背景中常见的“填充屏幕”行为(例如在 OS X 中)。
在投影仪中实现所需行为的干净方法是什么?
以下最小工作示例覆盖背景,但不按比例缩放(第一张幻灯片),或者按比例缩放图片,但既不使其居中,也不覆盖整个背景(第二张幻灯片):
\documentclass{beamer}
\usepackage{graphicx}
\begin{document}
{\usebackgroundtemplate{%
\includegraphics[width=\paperwidth,height=\paperheight]{test.jpg}}
\begin{frame}
\end{frame}}
{\usebackgroundtemplate{%
\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{test.jpg}}
\begin{frame}
\end{frame}}
\end{document}
幻灯片 1:
幻灯片 2:
答案1
\documentclass{beamer}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
{\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture, overlay]%
\node at (current page.center) {\includegraphics[width=.1\paperwidth,height=.1\paperheight,keepaspectratio]{tiger}};%
\end{tikzpicture}}
\begin{frame}
\end{frame}}
{\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture, overlay]%
\node at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{tiger}};%
\end{tikzpicture}}
\begin{frame}
\end{frame}}
\end{document}
\documentclass{beamer}
\usepackage{tikz}
\usepackage{graphicx}
\newlength{\picwidth}
\begin{document}
{\usebackgroundtemplate{%
\settowidth{\picwidth}{\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{tiger}}%
\ifdim\picwidth<\paperwidth
\begin{tikzpicture}[remember picture, overlay]%
\node at (current page.center) {\includegraphics[width=\paperwidth]{tiger}};%
\end{tikzpicture}%
\else
\begin{tikzpicture}[remember picture, overlay]%
\node at (current page.center) {\includegraphics[height=\paperheight]{tiger}};%
\end{tikzpicture}%
\fi
}
\begin{frame}
\end{frame}}
\end{document}
答案2
adjustbox
软件包中有一个min size
选项可以节省一些输入:
\documentclass{beamer}
\usepackage{tikz,adjustbox}
\begin{document}
\usebackgroundtemplate{%
\tikz[overlay,remember picture]%
\node[at=(current page.center)]{%
\adjustbox{min size={\paperwidth}{\paperheight}}%
{\includegraphics{PM5644.jpg}}};}
\begin{frame}
\end{frame}
\end{document}