Finally the definitive full-frame graphic commands for beamer in LaTeX

After my two (!) previous posts on the same topic, it’s time to give my final entry for the competition of the definitive full-frame graphics command for use with beamer in LaTeX. To seal the deal, I do not propose 1, but 4 commands, depending on your use case:

Download

Copy the command definitions from the last code block at the bottom of this post. The style definition for the overlay text ffgcaption in the first lines may be customised to mimic your presentation style. I opted for an unobtrusive, small overlay with white text over a semi-transparent black background in the slide’s bottom right corner.

Usage

The basic command has remained unchanged, and is to be called outside of a frame environment:

\fullframegraphic[optional credits argument]{path/to/image}

Exemplary result with a corny sample image:

However, it only works correctly if aspect ratio of the image matches your slide format (4:3, 16:10, 16:9 being the most common). If not, ugly white bars appear at the page borders.

If you do not want to manually crop all your images, I have prepared to more commands: for “tall” images, use the “w” for width variant: it automatically crops excess content top and bottom, and always displays the image at full frame width:

\fullframegraphicw[optional credits]{path/to/tall-image}

If instead you are blessed with “wide” images, use the “h” for height variant; it automatically crops excess content left and right and always displays the image at full frame height:

\fullframegraphich[optional credits]{path/to/wide-image}

If you need more customisation, use the “s” variant, whose third argument allows to add any content to the tikzpicture environment after the image has been placed. This example shows how to place a (heavily customised) tooltip node, manually placed using xshift and yshift, anywhere on the slide. For the other styles, you typically would want to define a custom style (similar to ffgcaption) to save you from typing:

\fullframegraphics[optional credits]{path/to/image}{%
    \node[at=(current page.north west),
          fill=green,
          fill opacity=.35,
          font=\footnotesize,
          inner xsep=3pt,
          inner ysep=5pt,
          rounded corners=1pt,
          text=black!75!green,
          text opacity=1,
          xshift=3.5cm,
          yshift=-0.9cm]
       {Tooltip!};
}

For a more full-blown usage example of the last command (including overlay specifications to uncover the tooltip), see file models.tex from the same repository.

References

Relevant questions on LaTeX Stack Exchange:

Command definitions

\usepackage[export]{adjustbox}
\tikzset{ffgcaption/.style={%
    anchor=south east,font=\tiny,
    text=white,fill=black,
    fill opacity=.5,text opacity=1,inner sep=2pt,
    text height=1ex,text depth=.25ex}}

% \fullframegraphic 
% renders a single image fullscreen, with an optional credit/caption in the 
% lower right corner.
% Usage: \fullframegraphic[some optional caption]{path/to/image}
% It does not crop the image, but leads to white borders if image does not match
% the aspect ratio of the slide. See commands \fullframegraphicw and
% \fullframegraphich below for cropping alternatives.
\newcommand{\fullframegraphic}[2][]{%
\begin{frame}[plain]%
\begin{tikzpicture}[remember picture,overlay]%
\node[at=(current page.center)] {%
\includegraphics[height=\paperheight,width=\paperwidth,keepaspectratio]{#2}%
};%
\ifx\relax#1\relax\else%
\node[at=(current page.south east),ffgcaption] {#1};%
\fi%
\end{tikzpicture}%
\end{frame}%
}

% \fullframegraphicw: scles image to frame width, cropping excess height.
% use for images that are "taller" than the frame aspect ratio
\newcommand{\fullframegraphicw}[2][]{%
\begin{frame}[plain]%
\begin{tikzpicture}[remember picture,overlay]%
\node[at=(current page.center)] {%
\includegraphics[min height=\paperheight,max width=\paperwidth,keepaspectratio]{#2}%
};%
\ifx\relax#1\relax\else%
\node[at=(current page.south east),ffgcaption] {#1};%
\fi%
\end{tikzpicture}%
\end{frame}%
}

% \fullframegraphich: scales image to frame height, cropping excess width.
% use for images that are wider than the frame aspect ratio
\newcommand{\fullframegraphich}[2][]{%
\begin{frame}[plain]%
\begin{tikzpicture}[remember picture,overlay]%
\node[at=(current page.center)] {%
\includegraphics[max height=\paperheight,min width=\paperwidth,keepaspectratio]{#2}%
};%
\ifx\relax#1\relax\else%
\node[at=(current page.south east),ffgcaption] {#1};%
\fi%
\end{tikzpicture}%
\end{frame}%
}

% \fullframegraphics: more customisable version of fullframegraphic, allowing
% a third argument to insert additional tikz commands for custom overlays.
% use when tooltips or highlights are required on a large image
\newcommand{\fullframegraphics}[3][]{%
\begin{frame}[plain]%
\begin{tikzpicture}[remember picture,overlay]%
\node[at=(current page.center)] {%
\includegraphics[height=\paperheight,width=\paperwidth,keepaspectratio]{#2}%
};%
\ifx\relax#1\relax\else%
\node[at=(current page.south east),ffgcaption] {#1};%
\fi%
#3%
\end{tikzpicture}%
\end{frame}%
}

Posted

in

,

by

Tags: