簡體   English   中英

指定自定義主題、序言的路徑,並包含在使用 R markdown 生成的 beamer 演示文稿的 YAML 標頭中

[英]Specify paths to custom theme, preamble and includes in YAML-header of beamer presentation generated with R markdown

在使用rmarkdown::beamer_presentation生成的 beamer 演示文稿中,我的目標是應用自定義主題,其中包含beamerthemeTHEMENAME.sty (帶有子文件beamercolorthemeTHEMENAME.stybeamerfontthemeTHEMENAME.stybeamerinnerthemeTHEMENAME.stybeamerouterthemeTHEMENAME.sty )作為template.tex包括.

目前,我在 YAML 標頭中獲取這些文件,如下所示:

theme: "THEMENAME"
template: template.tex
includes:
  in_header: preamble.tex
  before_body: before_body.tex
  after_body: after_body.tex

為了更整齊地組織演示文稿及其文件,我想移動這些文件...

  • 到演示目錄的子文件夾(短期解決方案

  • 到一個通用文件夾,這樣的模板同樣可以由其他演示文稿獲取/應用於其他演示文稿(長期解決方案)。

我將如何在每種情況下調整 YAML header 以正確獲取上述文件?

同時,我找到了一個短期有效的答案。
(有關長期解決方案的提示,請參閱@Steven 的回答和@Samcarter_is_at_topanswers.xyz 的評論。)

  • 將自定義主題THEMENAME的所有文件以及任何包含(例如, preamble.tex )放入演示文稿的 Rmd 文件所在文件夾中名為beamer_files的子文件夾中。

  • 修改 YAML header 和beamerthemeTHEMENAME.sty如下圖。 根據這些 SO 答案( LaTex themecolon ),一些 LaTex hack 是在rmarkdown::beamer_presentation中順利應用LaTex beamer theme所必需的。

MWE.Rmd

---
# COMMENT out "title" in YAML header: else markdown generates a second title page
# ==> if title contains no special characters: feed it straight into LaTex at the end of the YAML header
# ==> if title contains special characters, like ":", feed it in "preamble.tex" sourced in "LaTex Hacks"
subtitle: "Beamer presentation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  # beamer_presentation: default
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    # Source below in "LaTex Hacks", if want theme to be stored in subfolder (else rmarkdown does not find it)
    # theme: "THEMENAME"
    # Source "includes" below in "LaTex Hacks" if using custom theme with custom title page
    # => else, markdown places the includes at inadequate position in LaTex file, which then either does not show the title or throws an error
    # includes: ...
    latex_engine: xelatex
    toc: false
    slide_level: 2
classoption: aspectratio=169 # fix aspect ratio of presentation (169 => 16:9, 149 => 14:9, default: 4:3)
#
# LaTex Hacks
# --------------------------
compact-title: false # to remove markdown generated title frame
header-includes:
  # - \title{Title if no special characters} 
  - \input{beamer_files/beamerthemeTHEMENAME.sty}
  - \input{beamer_files/preamble}       # feed title to LaTex in preamble.tex due to ":"
  - \def\titlefigure{img/my_bg}
  - \AtBeginDocument{\titleframe} # add title frame defined in beamerouterthemeTHEMENAME
  - \makeatletter\beamer@ignorenonframefalse\makeatother
  ---


​```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
​```

<!-- TOC - Table of Contents -->
<!-- ======================================================== -->

``` {=latex}
\end{frame}
\tocframe
\begin{frame}
```

## Slide with Bullets
<!-- ======================================================== -->

- Bullet 1
- Bullet 2
- Bullet 3

<!-- Appendix -->
<!-- ======================================================== -->
``` {=latex}
\end{frame}
\appendix
\begin{frame}
```

beamerthemeTHEMENAME.sty

% WAS:
% \usecolortheme{THEMENAME}
% \useoutertheme{THEMENAME}
% NOW:
\input{beamer_files/beamercolorthemeTHEMENAME.sty}
\input{beamer_files/beamerouterthemeTHEMENAME.sty}

\mode<all>

序言.tex

% "title" is commented out in YAML header: else markdown generates a second title page
% if title contains no special characters: feed it straight into LaTex at the end of the YAML header
% if title contains special characters, like ":" or a forced linebreak feed it to LaTex here:
\title[short version]{First line of the title:\par second line of the title}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM