问题描述
我想在 rmarkdown::beamer_presentation
中应用 LaTex beamer 主题
.自定义主题包含 beamerthemeTHEMENAME.sty
、beamercolorthemeTHEMENAME.sty
、beamerfontthemeTHEMENAME.sty
、beamerinnerthemeTHEMENAME.sty
、beamerouterthemeTHEMENAME.sty.如果模板来源于我的 YAML 标头,则针织演示文稿看起来与通过应用自定义主题直接从 LaTex 生成的投影仪演示文稿不太接近.
因此,beamertheme*.sty
的哪些内容要修改或增强演示文稿需要修改或需要从 beamer 主题
中移动,例如到 template.tex
和 includes
*?
特别是,我正在努力使用 beamerouterthemeTHEMENAME.sty
中定义的以下框架模板:itleframe
、ocframe
、 closeframe
对于 beamerouterthemeTHEMENAME.sty
中定义的脚注,最好有一个从徽标到 table of contents
幻灯片的超链接(就像页码是链接到附录
).下面提供了 MWE.非常感谢任何帮助.
MWE.Rmd
---标题:MWE"副标题:带有 R-markdown 的 Beamer 预演"研究所:某个地方"日期:r格式(Sys.time(),'%B%d,%Y')"输出:# beamer_presentation: 默认bookdown::pdf_book:base_format: rmarkdown::beamer_presentation# 包括:# - in_header: preamble.tex主题:主题名称"latex_engine:xelatex目录:假幻灯片级别:2---```{r 设置,include=FALSE}knitr::opts_chunk$set(echo = FALSE)```# 随机呈现## TOC - 目录 {.unnumbered}目录标签{内容}## 用子弹滑动- 子弹 1- 子弹 2- 子弹 3## 附录附录
beamerthemeTHEMENAME.sty
usepackage[utf8]{inputenc}% Tizk, textpos, 图形RequirePackage{tikz}RequirePackage{文本位置}RequirePackage{xcolor}RequirePackage{booktabs}% 投影仪设置usecolortheme{主题名称}useoutertheme{主题名称}setbeamertemplate{导航符号}模式<全部>
beamercolorthemeTHEMENAME.sty
modedefinecolor{THEMECOL}{RGB}{162,48,47} % 红色definecolor{THEMEgray}{RGB}{110,110,101}% 灰色colorlet{titlefgcolor}{THEMECOL} % 盒子颜色colorlet{titlebgcolor}{THEMEgray} % 盒子颜色setbeamercolor*{title}{fg=THEMECOL} % 演示文稿标题setbeamercolor*{作者}{fg=THEMECOL} % 作者setbeamercolor*{日期}{fg=THEMECOL} % 日期模式<全部>
beamerouterthemeTHEMENAME.sty
mode% 重新定义 insertshortinstitute 以允许多行makeatletter
enewcommand{insertshortinstitute}{eamer@shortinstitute}makeatother% 标题框def itlefigure{img/my_bg}
ewlength itleboxwidthsetlength{ itleboxwidth}{0.33 extwidth}
ewcommand{ itleframe}{%{setbeamertemplate{背景}开始{tikzpicture}useasboundingbox (0,0) 矩形( hepaperwidth, hepaperheight);ifx itlefigure空fill[titlebgcolor] (6.3mm,6.4mm) 矩形 ( hepaperwidth-8.3mm, hepaperheight-13mm);别的
ode at (current page.center) [anchor=center,yshift=-3.5mm] {includegraphics[width= hepaperwidth-19mm]{ itlefigure}};fi
ode at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=fontsize{5.5}{6.6}selectfont]{插入短期研究所};
ode at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {includegraphics[高度=3.8mm]{img/my_logo}};结束{tikzpicture}}setbeamertemplate{脚线}egin{frame}[无帧编号]开始{tikzpicture}useasboundingbox (0,0) 矩形( hepaperwidth, hepaperheight);节点 [shift={(-11.5mm,-1.8mm)},填充=titlefgcolor,最小宽度=0.46纸张宽度,最小高度=18mm,锚=西,内间距=4mm] 在(当前 page.west){hspace*{9mm}egin{minipage}{ itleboxwidth}衣衫褴褛的权利usebeamerfont{title}usebeamercolor[fg]{title}inserttitle\[3mm]usebeamerfont{作者}usebeamercolor[fg]{作者}insertauthor\usebeamerfont{日期}usebeamercolor[fg]{日期}insertdateend{小页面}};结束{tikzpicture}结束{帧}}}% TOC 帧
ewcommand{ ocframe}{%开始{帧}frametitle{大纲}目录结束{帧}}% 章节标题框架AtBeginSection[]{开始{帧}frametitle{大纲}大 ableofcontents[当前部分]结束{帧}}新环境{关闭框架}{setbeamertemplate{背景}开始{tikzpicture}useasboundingbox (0,0) 矩形( hepaperwidth, hepaperheight);
ode at (current page.north west) [anchor=base west, xshift=8mm, yshift=-10mm, align=left] {includegraphics[宽度=23mm]{img/my_logo.png}};结束{tikzpicture}}setbeamertemplate{脚线}addtolength{headsep}{10mm}egin{frame}[无帧编号]}%{结束{帧}}%% 脚线setbeamertemplate{脚线}{离开模式%hyperlink{contents}{includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{img/my_logo.png}}hfillhyperlinkappendixstart{insertframenumber/inserttotalframenumber}vspace{3mm}}模式<全部>
你可以对 markdown 文档进行以下肮脏的 hack:
使用
AtBeginDocument{itle{MWE}itleframe}
代替 yaml 标题来抑制烦人的自动标题降价插入(甚至不使用maketitle
,因此无法进行任何合理的修改)并添加您的自定义标题命令AtEndDocument{egin{closureframe}lalalaend{closingframe}}
添加你的结束框架[用你喜欢的任何文本替换 lalala]添加
makeatlettereamer@ignorenonframefalsemakeatother
以抑制选项 markdown 烦人地自动使用并且不允许任何帧包装器你可以使用
``` {=latex}结束{帧} ocframe开始{帧}```
使用您的
ocframe
宏,但是我认为这没有多大用处,因为 markdown 会自动在所有合理的位置插入此类帧(然后在所有不合理的位置插入更多帧同样,只是因为它似乎喜欢被烦人......)
---副标题:带有 R-markdown 的 Beamer 预演"研究所:某个地方"日期:r格式(Sys.time(),'%B%d,%Y')"作者:《唐老鸭》输出:# beamer_presentation: 默认bookdown::pdf_book:base_format: rmarkdown::beamer_presentation# 包括:# in_header: preamble.tex主题:主题名称"latex_engine:xelatex目录:假幻灯片级别:2keep_tex: 真标头包括:- AtBeginDocument{ itle{MWE} itleframe}- AtEndDocument{egin{closureframe}lalalaend{closureframe}}- makeatlettereamer@ignorenonframefalsemakeatother---# 随机呈现## TOC - 目录 {.unnumbered}目录标签{内容}``` {=乳胶}结束{帧} ocframe开始{帧}```## 用子弹滑动- 子弹 1- 子弹 2- 子弹 3``` {=乳胶}结束{帧}附录开始{帧}```## 附录
现在进入主题:
如果你的 tex 发行版在恐龙灭绝后曾经更新过,那么你就不需要
usepackage[utf8]{inputenc}
.这是当前乳胶发行版中的默认设置.rmarkdown 也会自动插入.您不需要
RequirePackage{xcolor}
.beamer 不仅已经自动加载了它,而且它还会被包含在 rmarkdown 自动添加到文档中的这个令人讨厌的长不合适的包列表中.itleframe
宏也需要一些修改,因为主题确实滥用\
换行,并且不测试标题、作者和日期宏实际上是填充的.结合起来,这将非常失败......您可能还想为背景和标题框的字体使用不同的颜色......我在背景中混合了一点白色以使字体可见
ewcommand{ itleframe}{%{setbeamertemplate{背景}开始{tikzpicture}useasboundingbox (0,0) 矩形( hepaperwidth, hepaperheight);ifx itlefigure空fill[titlebgcolor] (6.3mm,6.4mm) 矩形 ( hepaperwidth-8.3mm, hepaperheight-13mm);别的
ode at (current page.center) [anchor=center,yshift=-3.5mm] {includegraphics[width= hepaperwidth-19mm]{ itlefigure}};fi
ode at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=fontsize{5.5}{6.6}selectfont]{插入短期研究所};
ode at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {includegraphics[height=3.8mm]{example-image}};结束{tikzpicture}}setbeamertemplate{脚线}egin{frame}[无帧编号]开始{tikzpicture}useasboundingbox (0,0) 矩形( hepaperwidth, hepaperheight);节点 [shift={(-11.5mm,-1.8mm)},填充=titlefgcolor!50!白色,最小宽度=0.46纸张宽度,最小高度=18mm,锚=西,内间距=4mm] 在(当前 page.west){hspace*{9mm}egin{minipage}{ itleboxwidth}衣衫褴褛的权利usebeamerfont{title}usebeamercolor[fg]{title}inserttitleparusebeamerfont{作者}usebeamercolor[fg]{作者}insertauthorparusebeamerfont{日期}usebeamercolor[fg]{日期}insertdateend{小页面}};结束{tikzpicture}结束{帧}}}
对于脚注,使用您的目录部分创建的超链接目标
% 脚注setbeamertemplate{脚线}{离开模式%hyperlink{toc---目录表}{includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{example-image}}hfillhyperlinkappendixstart{insertframenumber/inserttotalframenumber}vspace{3mm}}
[我猜我在这个答案中使用 annoying
的次数表明 rmarkdown 使在普通投影仪文档中需要 2 秒的工作变得更加困难]
I would like to apply a LaTex beamer theme
in an rmarkdown::beamer_presentation
.The custom themes contains a beamerthemeTHEMENAME.sty
, beamercolorthemeTHEMENAME.sty
, beamerfontthemeTHEMENAME.sty
, beamerinnerthemeTHEMENAME.sty
, beamerouterthemeTHEMENAME.sty
.If the template is sourced within my YAML header, the knitted presentation does not look very close to a beamer presentation generated straight from LaTex by applying the custom theme.
Thus, which contents of the beamertheme*.sty
to modify or enhance the presentation require modification or need to be moved from the beamer theme
, e.g. to template.tex
and includes
*?
In particular, I am struggling on using the following frame templates defined in beamerouterthemeTHEMENAME.sty
: itleframe
, ocframe
, closingframe
For the footline defined in beamerouterthemeTHEMENAME.sty
, it would be very nice to have a hyperlink from the logo to the table of contents
slide (like the page numbers are linked to the appendix
).An MWE is provided below. Any help is greatly appreciated.
MWE.Rmd
---
title: "MWE"
subtitle: "Beamer presnetation 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
# includes:
# - in_header: preamble.tex
theme: "THEMENAME"
latex_engine: xelatex
toc: false
slide_level: 2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Random presentation
## TOC - Table of Contents {.unnumbered}
ableofcontents
label{contents}
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
## Apendix
appendix
beamerthemeTHEMENAME.sty
usepackage[utf8]{inputenc}
% Tizk, textpos, graphics
RequirePackage{tikz}
RequirePackage{textpos}
RequirePackage{xcolor}
RequirePackage{booktabs}
% Beamer settings
usecolortheme{THEMENAME}
useoutertheme{THEMENAME}
setbeamertemplate{navigation symbols}{}
mode<all>
beamercolorthemeTHEMENAME.sty
mode<presentation>
definecolor{THEMECOL}{RGB}{162,48,47} % red
definecolor{THEMEgray}{RGB}{110,110,101}% gray
colorlet{titlefgcolor}{THEMECOL} % color of box
colorlet{titlebgcolor}{THEMEgray} % color of box
setbeamercolor*{title}{fg=THEMECOL} % presentation title
setbeamercolor*{author}{fg=THEMECOL} % author
setbeamercolor*{date}{fg=THEMECOL} % date
mode<all>
beamerouterthemeTHEMENAME.sty
mode<presentation>
% Redefine insertshortinstitute to allow multiple lines
makeatletter
enewcommand{insertshortinstitute}{eamer@shortinstitute}
makeatother
% Title frame
def itlefigure{img/my_bg}
ewlength itleboxwidth
setlength{ itleboxwidth}{0.33 extwidth}
ewcommand{ itleframe}{%
{
setbeamertemplate{background}{
egin{tikzpicture}
useasboundingbox (0,0) rectangle( hepaperwidth, hepaperheight);
ifx itlefigureempty
fill[titlebgcolor] (6.3mm,6.4mm) rectangle ( hepaperwidth-8.3mm, hepaperheight-13mm);
else
ode at (current page.center) [anchor=center,yshift=-3.5mm] {includegraphics[width= hepaperwidth-19mm]{ itlefigure}};
fi
ode at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=fontsize{5.5}{6.6}selectfont] {
insertshortinstitute
};
ode at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {
includegraphics[height=3.8mm]{img/my_logo}
};
end{tikzpicture}
}
setbeamertemplate{footline}{}
egin{frame}[noframenumbering]
egin{tikzpicture}
useasboundingbox (0,0) rectangle( hepaperwidth, hepaperheight);
ode [
shift={(-11.5mm,-1.8mm)},
fill=titlefgcolor,
minimum width=0.46paperwidth,
minimum height=18mm,
anchor=west,
inner sep=4mm
] at (current page.west) {
hspace*{9mm}
egin{minipage}{ itleboxwidth}
aggedright
usebeamerfont{title}usebeamercolor[fg]{title}inserttitle\[3mm]
usebeamerfont{author}usebeamercolor[fg]{author}insertauthor\
usebeamerfont{date}usebeamercolor[fg]{date}insertdate
end{minipage}
};
end{tikzpicture}
end{frame}
}
}
% TOC frame
ewcommand{ ocframe}{%
egin{frame}
frametitle{Outline}
ableofcontents
end{frame}
}
% Section title frame
AtBeginSection[]
{
egin{frame}
frametitle{Outline}
large
ableofcontents[currentsection]
end{frame}
}
ewenvironment{closingframe}{
setbeamertemplate{background}{
egin{tikzpicture}
useasboundingbox (0,0) rectangle( hepaperwidth, hepaperheight);
ode at (current page.north west) [anchor=base west, xshift=8mm, yshift=-10mm, align=left] {
includegraphics[width=23mm]{img/my_logo.png}
};
end{tikzpicture}
}
setbeamertemplate{footline}{}
addtolength{headsep}{10mm}
egin{frame}[noframenumbering]
}%
{
end{frame}
}%
% Footline
setbeamertemplate{footline}{
leavevmode%
hyperlink{contents}{includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{img/my_logo.png}}
hfill
hyperlinkappendixstart{insertframenumber/inserttotalframenumber}
vspace{3mm}
}
mode<all>
You can make the following dirty hacks to the markdown document:
Instead of the yaml title, use
AtBeginDocument{itle{MWE}itleframe}
to suppress the annoying automatic title markdown inserts (which does not even usesmaketitle
, so one can't make any reasonable modifications) and add your custom title commandAtEndDocument{egin{closingframe}lalalaend{closingframe}}
to add your closing frame [replace lalala with whatever text you like]add
makeatlettereamer@ignorenonframefalsemakeatother
to suppress options markdown annoyingly automatically uses and which don't allow any wrappers for framesyou can use
``` {=latex} end{frame} ocframe egin{frame} ```
to use your
ocframe
macro, however I don't see much use for this, as markdown will automatically insert such frames at all reasonable places (and then a couple of more at all unreasonable places as well, just because it seems to enjoy being annoying...)
---
subtitle: "Beamer presnetation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
author: "Donald Duck"
output:
# beamer_presentation: default
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
# includes:
# in_header: preamble.tex
theme: "THEMENAME"
latex_engine: xelatex
toc: false
slide_level: 2
keep_tex: true
header-includes:
- AtBeginDocument{ itle{MWE} itleframe}
- AtEndDocument{egin{closingframe}lalalaend{closingframe}}
- makeatlettereamer@ignorenonframefalsemakeatother
---
# Random presentation
## TOC - Table of Contents {.unnumbered}
ableofcontents
label{contents}
``` {=latex}
end{frame}
ocframe
egin{frame}
```
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
``` {=latex}
end{frame}
appendix
egin{frame}
```
## Apendix
Now to the theme:
if your tex distribution has been updated at one point since the dinosaurs gone extinction, then you don't need
usepackage[utf8]{inputenc}
. That's the default in current latex distributions. Also rmarkdown will automatically insert this.you don't need
RequirePackage{xcolor}
. Not only does beamer already load this automatically, but it will also be included in this annoyingly long list of unsuitable packages rmarkdown automatically adds to the document.The
itleframe
macro also needs a couple of modifications because the theme does abuse\
for line breaks and does not test if title, author and date macros are actually filled. Combined this will fail spectacularly...you might also want to use different colours for the background and the font of the title box.... I mixed a bit of white to the background to make the font visible
ewcommand{ itleframe}{%
{
setbeamertemplate{background}{
egin{tikzpicture}
useasboundingbox (0,0) rectangle( hepaperwidth, hepaperheight);
ifx itlefigureempty
fill[titlebgcolor] (6.3mm,6.4mm) rectangle ( hepaperwidth-8.3mm, hepaperheight-13mm);
else
ode at (current page.center) [anchor=center,yshift=-3.5mm] {includegraphics[width= hepaperwidth-19mm]{ itlefigure}};
fi
ode at (current page.north east) [anchor=base east, xshift=-8.3mm, yshift=-6.3mm, align=left, inner sep=0mm, font=fontsize{5.5}{6.6}selectfont] {
insertshortinstitute
};
ode at (current page.north west) [anchor=south west, inner sep=0mm, xshift=8.3mm, yshift=-8.6mm] {
includegraphics[height=3.8mm]{example-image}
};
end{tikzpicture}
}
setbeamertemplate{footline}{}
egin{frame}[noframenumbering]
egin{tikzpicture}
useasboundingbox (0,0) rectangle( hepaperwidth, hepaperheight);
ode [
shift={(-11.5mm,-1.8mm)},
fill=titlefgcolor!50!white,
minimum width=0.46paperwidth,
minimum height=18mm,
anchor=west,
inner sep=4mm
] at (current page.west) {
hspace*{9mm}
egin{minipage}{ itleboxwidth}
aggedright
usebeamerfont{title}usebeamercolor[fg]{title}inserttitlepar
usebeamerfont{author}usebeamercolor[fg]{author}insertauthorpar
usebeamerfont{date}usebeamercolor[fg]{date}insertdate
end{minipage}
};
end{tikzpicture}
end{frame}
}
}
For the footline, use the hyperlink target that is created by your toc section
% Footline
setbeamertemplate{footline}{
leavevmode%
hyperlink{toc---table-of-contents}{includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{example-image}}
hfill
hyperlinkappendixstart{insertframenumber/inserttotalframenumber}
vspace{3mm}
}
[I guess the number of times I used annoying
in this answer shows how much more difficult rmarkdown makes a job that would have taken 2 seconds in a normal beamer document]
这篇关于如何调整 LaTex beamer 主题以将其应用于 rmarkdown::beamer_presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!