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

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

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

问题

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

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

最小示例

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

example-slides.qmd

  1. ---
  2. title: 你好和再见!
  3. author: 我的名字
  4. institute: 我的研究机构
  5. format:
  6. myextension-beamer
  7. ---
  8. # 你好
  9. Hello在德语中是“Guten Tag!”
  10. # 再见
  11. 谢谢您的关注!

_extensions/myextension/_extension.yml

  1. title: 自定义Beamer
  2. author: 我可恶
  3. quarto-required: ">=1.2.0"
  4. version: 1.0.0
  5. contributes:
  6. formats:
  7. pdf: default
  8. beamer:
  9. aspectratio: 169
  10. background-image: gray-background.png
  11. include-in-header:
  12. - file: preamble-beamer.tex

_extensions/myextension/preamble-beamer.tex

  1. % 页码
  2. \setbeamertemplate{footline}{%
  3. \leavevmode%
  4. \hbox{%
  5. \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
  6. \usebeamerfont{author in head/foot}%
  7. \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
  8. \end{beamercolorbox}%
  9. }%
  10. \vskip0pt%
  11. }

_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

  1. ---
  2. title: Hello and Bye!
  3. author: My Name
  4. institute: My Institute
  5. format:
  6. myextension-beamer
  7. ---
  8. # Hello
  9. Hello is in German "Guten Tag!"
  10. # Good Bye
  11. Thank you for your attention!

_extensions/myextension/_extension.yml

  1. title: Custom Beamer
  2. author: Me Despicable
  3. quarto-required: ">=1.2.0"
  4. version: 1.0.0
  5. contributes:
  6. formats:
  7. pdf: default
  8. beamer:
  9. aspectratio: 169
  10. background-image: gray-background.png
  11. include-in-header:
  12. - file: preamble-beamer.tex

_extensions/myextension/preamble-beamer.tex

  1. % Page numbering
  2. \setbeamertemplate{footline}{%
  3. \leavevmode%
  4. \hbox{%
  5. \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
  6. \usebeamerfont{author in head/foot}%
  7. \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
  8. \end{beamercolorbox}%
  9. }%
  10. \vskip0pt%
  11. }

_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将背景图像缩放以填满整个页面。

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

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

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

完整示例:

  1. % Packages and configuration...
  2. \documentclass[
  3. ignorenonframetext,
  4. aspectratio=169,
  5. ]{beamer}
  6. \usebackgroundtemplate{%
  7. \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{gray-background.png}%
  8. }
  9. % Rest of the document...
  10. \begin{document}
  11. % Slides...
  12. \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

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

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

Full example:

  1. % Options for packages loaded elsewhere
  2. \PassOptionsToPackage{unicode}{hyperref}
  3. \PassOptionsToPackage{hyphens}{url}
  4. %
  5. \documentclass[
  6. ignorenonframetext,
  7. aspectratio=169,
  8. ]{beamer}
  9. \usebackgroundtemplate{%
  10. \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{gray-background.png}%
  11. }
  12. \usepackage{pgfpages}
  13. \setbeamertemplate{caption}[numbered]
  14. \setbeamertemplate{caption label separator}{: }
  15. \setbeamercolor{caption name}{fg=normal text.fg}
  16. \beamertemplatenavigationsymbolsempty
  17. % Prevent slide breaks in the middle of a paragraph
  18. \widowpenalties 1 10000
  19. \raggedbottom
  20. \setbeamertemplate{part page}{
  21. \centering
  22. \begin{beamercolorbox}[sep=16pt,center]{part title}
  23. \usebeamerfont{part title}\insertpart\par
  24. \end{beamercolorbox}
  25. }
  26. \setbeamertemplate{section page}{
  27. \centering
  28. \begin{beamercolorbox}[sep=12pt,center]{part title}
  29. \usebeamerfont{section title}\insertsection\par
  30. \end{beamercolorbox}
  31. }
  32. \setbeamertemplate{subsection page}{
  33. \centering
  34. \begin{beamercolorbox}[sep=8pt,center]{part title}
  35. \usebeamerfont{subsection title}\insertsubsection\par
  36. \end{beamercolorbox}
  37. }
  38. \AtBeginPart{
  39. \frame{\partpage}
  40. }
  41. \AtBeginSection{
  42. \ifbibliography
  43. \else
  44. \frame{\sectionpage}
  45. \fi
  46. }
  47. \AtBeginSubsection{
  48. \frame{\subsectionpage}
  49. }
  50. \usepackage{amsmath,amssymb}
  51. \usepackage{lmodern}
  52. \usepackage{iftex}
  53. \ifPDFTeX
  54. \usepackage[T1]{fontenc}
  55. \usepackage[utf8]{inputenc}
  56. \usepackage{textcomp} % provide euro and other symbols
  57. \else % if luatex or xetex
  58. \usepackage{unicode-math}
  59. \defaultfontfeatures{Scale=MatchLowercase}
  60. \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
  61. \fi
  62. % Use upquote if available, for straight quotes in verbatim environments
  63. \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
  64. \IfFileExists{microtype.sty}{% use microtype if available
  65. \usepackage[]{microtype}
  66. \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
  67. }{}
  68. \makeatletter
  69. \@ifundefined{KOMAClassName}{% if non-KOMA class
  70. \IfFileExists{parskip.sty}{%
  71. \usepackage{parskip}
  72. }{% else
  73. \setlength{\parindent}{0pt}
  74. \setlength{\parskip}{6pt plus 2pt minus 1pt}}
  75. }{% if KOMA class
  76. \KOMAoptions{parskip=half}}
  77. \makeatother
  78. \usepackage{xcolor}
  79. \newif\ifbibliography
  80. \setlength{\emergencystretch}{3em} % prevent overfull lines
  81. \setcounter{secnumdepth}{-\maxdimen} % remove section numbering
  82. \providecommand{\tightlist}{%
  83. \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
  84. \usepackage{calc} % for calculating minipage widths
  85. \usepackage{caption}
  86. % Make caption package work with longtable
  87. \makeatletter
  88. \def\fnum@table{\tablename~\thetable}
  89. \makeatother
  90. \usepackage{graphicx}
  91. \makeatletter
  92. \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
  93. \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
  94. \makeatother
  95. % Scale images if necessary, so that they will not overflow the page
  96. % margins by default, and it is still possible to overwrite the defaults
  97. % using explicit options in \includegraphics[width, height, ...]{}
  98. \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
  99. % Set default figure placement to htbp
  100. \makeatletter
  101. \def\fps@figure{htbp}
  102. \makeatother
  103. % Page numbering
  104. \setbeamertemplate{footline}{%
  105. \leavevmode%
  106. \hbox{%
  107. \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
  108. \usebeamerfont{author in head/foot}%
  109. \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
  110. \end{beamercolorbox}%
  111. }%
  112. \vskip0pt%
  113. }
  114. \makeatletter
  115. \makeatother
  116. \makeatletter
  117. \makeatother
  118. \makeatletter
  119. \@ifpackageloaded{caption}{}{\usepackage{caption}}
  120. \AtBeginDocument{%
  121. \ifdefined\contentsname
  122. \renewcommand*\contentsname{Table of contents}
  123. \else
  124. \newcommand\contentsname{Table of contents}
  125. \fi
  126. \ifdefined\listfigurename
  127. \renewcommand*\listfigurename{List of Figures}
  128. \else
  129. \newcommand\listfigurename{List of Figures}
  130. \fi
  131. \ifdefined\listtablename
  132. \renewcommand*\listtablename{List of Tables}
  133. \else
  134. \newcommand\listtablename{List of Tables}
  135. \fi
  136. \ifdefined\figurename
  137. \renewcommand*\figurename{Figure}
  138. \else
  139. \newcommand\figurename{Figure}
  140. \fi
  141. \ifdefined\tablename
  142. \renewcommand*\tablename{Table}
  143. \else
  144. \newcommand\tablename{Table}
  145. \fi
  146. }
  147. \@ifpackageloaded{float}{}{\usepackage{float}}
  148. \floatstyle{ruled}
  149. \@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}
    }
  150. \floatname{codelisting}{Listing}
  151. \newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
  152. \makeatother
  153. \makeatletter
  154. \@ifpackageloaded{caption}{}{\usepackage{caption}}
  155. \@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
  156. \makeatother
  157. \makeatletter
  158. \@ifpackageloaded{tcolorbox}{}{\usepackage[many]{tcolorbox}}
  159. \makeatother
  160. \makeatletter
  161. \@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}
  162. \makeatother
  163. \makeatletter
  164. \makeatother
  165. \ifLuaTeX
  166. \usepackage{selnolig} % disable illegal ligatures
  167. \fi
  168. \IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
  169. \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
  170. \urlstyle{same} % disable monospaced font for URLs
  171. \hypersetup{
  172. pdftitle={Hello and Bye!},
  173. pdfauthor={My Name},
  174. hidelinks,
  175. pdfcreator={LaTeX via pandoc}}
  176. \title{Hello and Bye!}
  177. \author{My Name}
  178. \date{}
  179. \institute{My Institute}
  180. \begin{document}
  181. \frame{\titlepage}
  182. \ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[sharp corners, boxrule=0pt, interior hidden, borderline west={3pt}{0pt}{shadecolor}, enhanced, breakable, frame hidden]}{\end{tcolorbox}}\fi
  183. \begin{frame}{Hello}
  184. \protect\hypertarget{hello}{}
  185. Hello is in German ``Guten Tag!''
  186. \end{frame}
  187. \begin{frame}{Good Bye}
  188. \protect\hypertarget{good-bye}{}
  189. Thank you for your attention!
  190. \end{frame}
  191. \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:

确定