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

huangapple go评论53阅读模式
英文:

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

问题

我使用Quarto扩展自定义了一个beamer演示文稿。默认的帧(幻灯片)会有一个在**_extension.yml**文件中设置的背景图像。问题是设置的图像未覆盖整个帧。显然,底部的空白导航栏和幻灯片底部的脚注未与背景重叠(请参见幻灯片底部的页码):

我认为,解决方案应该应用于项目中的LaTeX导言部分(tex文件),但我不知道如何做。

最小示例

与主项目文件夹相关的路径包括在文件名中:

example-slides.qmd

---
title: 你好和再见!
author: 我的名字
institute: 我的研究机构
format: 
  myextension-beamer
---


# 你好

Hello在德语中是“Guten Tag!”


# 再见

谢谢您的关注!

_extensions/myextension/_extension.yml

title: 自定义Beamer
author: 我可恶
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

% 页码
\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

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):

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

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

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

答案1

得分: 1

问题在于Quarto添加了以下行\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio},这实际上不是一个好主意,因为它阻止了LaTeX将背景图像缩放以填满整个页面。

你可以通过明确设置背景图像的高度和宽度来解决这个问题,如下所示:

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

而不是使用Quarto选项background-image: gray-background.png

完整示例:

% Packages and configuration...
\documentclass[
  ignorenonframetext,
  aspectratio=169,
]{beamer}
\usebackgroundtemplate{%
  \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{gray-background.png}%
}
% Rest of the document...
\begin{document}
% Slides...
\end{document}

请注意,此处只提供了需要翻译的部分。如果您需要其他帮助,请告诉我。

英文:

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}
} \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}

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

huangapple
  • 本文由 发表于 2023年6月5日 17:05:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404922.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定