Search code examples
latexmarkdownquarto

Background image for beamer set in quarto is not covering the full slides


I customize a beamer presentation using quarto extensions. Default frames (slides) will have a background image which is set in a file _extension.yml. The problem is that the set image is not covering the full frame. Apparently the empty navigation bar and the footline on the bottom of the slide are not overlapped to the background (see page number at the bottom of the slide):

enter image description here

I assume, a solution have to be applied to the LaTeX preamble (tex-file) in the project but I don't know how.

Minimal Example

The paths relative to the main project folder are included in the file names:

example-slides.qmd

---
title: Hello and Bye!
author: My Name
institute: My Institute
format: 
  myextension-beamer
---


# Hello

Hello is in German "Guten Tag!"


# Good Bye

Thank you for your attention!

_extensions/myextension/_extension.yml

title: Custom Beamer
author: Me Despicable
quarto-required: ">=1.2.0"
version: 1.0.0
contributes: 
  formats: 
    pdf: default
    beamer:
      aspectratio: 169
      background-image: gray-background.png
      include-in-header:
        - file: preamble-beamer.tex

_extensions/myextension/preamble-beamer.tex

% Page numbering
\setbeamertemplate{footline}{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
            \usebeamerfont{author in head/foot}%
            \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
        \end{beamercolorbox}%
    }%
    \vskip0pt%
}

_extensions/myextension/gray-background.png

enter image description here


Solution

  • The problem is that Quarto adds the line \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}, which is really not a good idea because it prevents latex from scaling the background image to fill the whole page.

    You can work around this problem by explicitly setting the height as well as the width of the background image with

    \usebackgroundtemplate{%
      \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{\_extensions/myextension/gray-background.png}%
    }
    

    instead of using the quarto option background-image: gray-background.png

    Full example:

    % Options for packages loaded elsewhere
    \PassOptionsToPackage{unicode}{hyperref}
    \PassOptionsToPackage{hyphens}{url}
    %
    \documentclass[
      ignorenonframetext,
      aspectratio=169,
    ]{beamer}
    \usebackgroundtemplate{%
      \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{gray-background.png}%
    }
    \usepackage{pgfpages}
    \setbeamertemplate{caption}[numbered]
    \setbeamertemplate{caption label separator}{: }
    \setbeamercolor{caption name}{fg=normal text.fg}
    \beamertemplatenavigationsymbolsempty
    % Prevent slide breaks in the middle of a paragraph
    \widowpenalties 1 10000
    \raggedbottom
    \setbeamertemplate{part page}{
      \centering
      \begin{beamercolorbox}[sep=16pt,center]{part title}
        \usebeamerfont{part title}\insertpart\par
      \end{beamercolorbox}
    }
    \setbeamertemplate{section page}{
      \centering
      \begin{beamercolorbox}[sep=12pt,center]{part title}
        \usebeamerfont{section title}\insertsection\par
      \end{beamercolorbox}
    }
    \setbeamertemplate{subsection page}{
      \centering
      \begin{beamercolorbox}[sep=8pt,center]{part title}
        \usebeamerfont{subsection title}\insertsubsection\par
      \end{beamercolorbox}
    }
    \AtBeginPart{
      \frame{\partpage}
    }
    \AtBeginSection{
      \ifbibliography
      \else
        \frame{\sectionpage}
      \fi
    }
    \AtBeginSubsection{
      \frame{\subsectionpage}
    }
    
    \usepackage{amsmath,amssymb}
    \usepackage{lmodern}
    \usepackage{iftex}
    \ifPDFTeX
      \usepackage[T1]{fontenc}
      \usepackage[utf8]{inputenc}
      \usepackage{textcomp} % provide euro and other symbols
    \else % if luatex or xetex
      \usepackage{unicode-math}
      \defaultfontfeatures{Scale=MatchLowercase}
      \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
    \fi
    % Use upquote if available, for straight quotes in verbatim environments
    \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
    \IfFileExists{microtype.sty}{% use microtype if available
      \usepackage[]{microtype}
      \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
    }{}
    \makeatletter
    \@ifundefined{KOMAClassName}{% if non-KOMA class
      \IfFileExists{parskip.sty}{%
        \usepackage{parskip}
      }{% else
        \setlength{\parindent}{0pt}
        \setlength{\parskip}{6pt plus 2pt minus 1pt}}
    }{% if KOMA class
      \KOMAoptions{parskip=half}}
    \makeatother
    \usepackage{xcolor}
    \newif\ifbibliography
    \setlength{\emergencystretch}{3em} % prevent overfull lines
    \setcounter{secnumdepth}{-\maxdimen} % remove section numbering
    
    
    \providecommand{\tightlist}{%
      \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
    \usepackage{calc} % for calculating minipage widths
    \usepackage{caption}
    % Make caption package work with longtable
    \makeatletter
    \def\fnum@table{\tablename~\thetable}
    \makeatother
    \usepackage{graphicx}
    \makeatletter
    \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
    \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
    \makeatother
    % Scale images if necessary, so that they will not overflow the page
    % margins by default, and it is still possible to overwrite the defaults
    % using explicit options in \includegraphics[width, height, ...]{}
    \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
    % Set default figure placement to htbp
    \makeatletter
    \def\fps@figure{htbp}
    \makeatother
    
    % Page numbering
    \setbeamertemplate{footline}{%
        \leavevmode%
        \hbox{%
            \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
                \usebeamerfont{author in head/foot}%
                \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
            \end{beamercolorbox}%
        }%
        \vskip0pt%
    }
    \makeatletter
    \makeatother
    \makeatletter
    \makeatother
    \makeatletter
    \@ifpackageloaded{caption}{}{\usepackage{caption}}
    \AtBeginDocument{%
    \ifdefined\contentsname
      \renewcommand*\contentsname{Table of contents}
    \else
      \newcommand\contentsname{Table of contents}
    \fi
    \ifdefined\listfigurename
      \renewcommand*\listfigurename{List of Figures}
    \else
      \newcommand\listfigurename{List of Figures}
    \fi
    \ifdefined\listtablename
      \renewcommand*\listtablename{List of Tables}
    \else
      \newcommand\listtablename{List of Tables}
    \fi
    \ifdefined\figurename
      \renewcommand*\figurename{Figure}
    \else
      \newcommand\figurename{Figure}
    \fi
    \ifdefined\tablename
      \renewcommand*\tablename{Table}
    \else
      \newcommand\tablename{Table}
    \fi
    }
    \@ifpackageloaded{float}{}{\usepackage{float}}
    \floatstyle{ruled}
    \@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
    \floatname{codelisting}{Listing}
    \newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
    \makeatother
    \makeatletter
    \@ifpackageloaded{caption}{}{\usepackage{caption}}
    \@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
    \makeatother
    \makeatletter
    \@ifpackageloaded{tcolorbox}{}{\usepackage[many]{tcolorbox}}
    \makeatother
    \makeatletter
    \@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}
    \makeatother
    \makeatletter
    \makeatother
    \ifLuaTeX
      \usepackage{selnolig}  % disable illegal ligatures
    \fi
    \IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
    \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
    \urlstyle{same} % disable monospaced font for URLs
    \hypersetup{
      pdftitle={Hello and Bye!},
      pdfauthor={My Name},
      hidelinks,
      pdfcreator={LaTeX via pandoc}}
    
    \title{Hello and Bye!}
    \author{My Name}
    \date{}
    \institute{My Institute}
    
    
    \begin{document}
    \frame{\titlepage}
    \ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[sharp corners, boxrule=0pt, interior hidden, borderline west={3pt}{0pt}{shadecolor}, enhanced, breakable, frame hidden]}{\end{tcolorbox}}\fi
    
    \begin{frame}{Hello}
    \protect\hypertarget{hello}{}
    Hello is in German ``Guten Tag!''
    \end{frame}
    
    \begin{frame}{Good Bye}
    \protect\hypertarget{good-bye}{}
    Thank you for your attention!
    \end{frame}
    
    
    
    \end{document}
    

    enter image description here