r - 指定自定义主题、序言和包含在使用 R 降价生成的 beamer 演示文稿的 YAML 标头中的路径
问题描述
在使用 生成的投影仪演示文稿中rmarkdown::beamer_presentation
,我的目标是应用一个自定义主题,其中包含一个beamerthemeTHEMENAME.sty
(带有子文件beamercolorthemeTHEMENAME.sty
, beamerfontthemeTHEMENAME.sty
, beamerinnerthemeTHEMENAME.sty
, beamerouterthemeTHEMENAME.sty
),作为 a template.tex
和Includes。
目前我在 YAML-header 中获取这些文件,如下所示:
theme: "THEMENAME"
template: template.tex
includes:
in_header: preamble.tex
before_body: before_body.tex
after_body: after_body.tex
为了更整齐地组织演示文稿及其文件,我想移动这些文件......
到演示目录的子文件夹(短期解决方案)
到一个通用文件夹,这样的模板同样可以由其他演示文稿获取/应用于其他演示文稿(长期解决方案)。
在每种情况下,我将如何调整 YAML 标头以正确获取上述文件?
解决方案
同时,我找到了一个短期内有效的答案。
(有关长期解决方案的提示,请参阅@Steven 的回答和@Samcarter_is_at_topanswers.xyz 的评论。)
将自定义主题的所有文件
THEMENAME
以及任何包含(例如,preamble.tex
)beamer_files
拖放到演示文稿的 Rmd 文件所在的文件夹中称为子文件夹中。修改 YAML 标头,
beamerthemeTHEMENAME.sty
如下所示。根据这些 SO 答案(LaTex 主题、冒号),需要一些 LaTex hacks 才能LaTex beamer theme
顺利应用rmarkdown::beamer_presentation
.
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}
推荐阅读
- java - 在 java swing 面板中放置按钮的布局
- html - How to create grid inside a bootstrap 3 modal
- javascript - 如何使用 Perfume.js 测量小部件/组件的性能
- ruby-on-rails - 在浏览器中输出 URL / 视图 - 来自 Rails .html.erb
- sql - Oracle 选择计数 > 1
- python-3.x - 提取 matplotlib.markers 符号及其标记
- python - Python.PY 代码中 print() 中不存在的变量
- java - Java/Selenium:方法中尚未定义的类的实例
- mongodb - Mongo Shell 更新嵌套的文档数组
- django - Django保存到数据库