本文介绍了在ToC之后删除其他空白幻灯片,并使用自定义的投影仪主题在rmarkdown :: beamer_presentation中插入黑色幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 rmarkdown :: beamer_presentation 中使用了自定义的 LaTex投影仪主题.根据这些SO答案(

图2:在YAML标头中使用 toc:true 生成ToC

MWE.Rmd

  ---#注释掉标题";在YAML标头中:否则markdown生成第二张标题幻灯片#==>如果标题不包含特殊字符:将其直接输入到YAML标头末尾的LaTex中#==>如果标题包含特殊字符(如:"),则将其输入"preamble.tex"源于"LaTex Hacks"副标题:带有R-markdown的光束演示"研究所:某处"日期:`r format(Sys.time(),'%​​B%d,%Y')`";输出:#beamer_presentation:默认bookdown :: pdf_book:base_format:rmarkdown :: beamer_presentation#如果希望将主题存储在子文件夹中,则"LaTex Hacks"中的以下来源(否则rmarkdown找不到它)#主题:"THEMENAME";# 来源包括"下面的"LaTex Hacks"中如果将自定义主题与自定义标题页一起使用#=>否则,降价会将包含文件放置在LaTex文件中的不适当位置,然后该文件不显示标题或引发错误#包括:...latex_engine:xelatextoc:false#使用LaTex TOC(其他垂直对齐方式混乱而不是标题)slide_level:2classoption:Aspectratio = 169#修复演示的宽高比(169 => 16:9,149 => 14:9,默认值:4:3)##LaTex骇客#--------------------------compact-title:false#删除markdown生成的标题框架标头包括:#-\ title {如果没有特殊字符则加标题}-\ input {beamer_files/beamerthemeTHEMENAME.sty}-\ input {beamer_files/preamble}#由于:",在preamble.tex中为LaTex提供了标题.-\ def \ titlefigure {img/my_bg}-\ AtBeginDocument {\ titleframe}#添加在beamerouterthemeTHEMENAME中定义的标题框架-\ makeatletter \ beamer @ ignorenonframefalse \ makeatother---``{r setup,include = FALSE}knitr :: opts_chunk $ set(echo = FALSE)```<!-目录-目录-><!-=======================================================-```{=乳胶}\ end {frame}\ tocframe\ begin {frame}```##带子弹滑<!-=======================================================--子弹1-第2弹-子弹3<!-附录-><!-=======================================================-```{=乳胶}\ end {frame}\附录\ begin {frame}``` 

beamerthemeTHEMENAME.sty

  \ mode< presentation>%Tizk,textpos,图形\ RequirePackage {tikz}\ RequirePackage {textpos}\RequirePackage{booktabs}投影机设置百分比\ input {beamer_files/beamercolorthemeTHEMENAME.sty}\ input {beamer_files/beamerouterthemeTHEMENAME.sty}\ setbeamertemplate {导航符号} {}\ mode< all> 

beamerouterthemeTHEMENAME.sty

  \ mode< presentation>%重新定义\ insertshortinstitute以允许多行\ makeatletter\ renewcommand {\ insertshortinstitute} {\ beamer @ shortinstitute}\ makeatother%标题框\ def \ titlefigure {img/my_bg}\ newlength \ titleboxwidth\ setlength {\ titleboxwidth} {0.43 \ textwidth}\ newcommand {\ titleframe} {%{\setbeamertemplate{背景}{\ begin {tikzpicture}\useasboundingbox (0,0) 矩形(\the\paperwidth,\the\paperheight);\ ifx \ titlefigure \ empty\ fill [titlebgcolor](6.3mm,6.4mm)矩形(\ the \ paperwidth-8.3mm,\ the \ paperheight-13mm);\别的\ node在(当前page.center)处[anchor = center,yshift = -3.5mm] {\ includegraphics [width = \ the \ paperwidth-19mm] {\ titlefigure}};\ fi\ node位于(当前页面.东北)[锚点=东边,xshift = -8.3mm,yshift = -6.3mm,align = left,内部sep = 0mm,font = \ fontsize {5.5} {6.6} \ selectfont]{\ insertshortinstitute};\ node位于(当前页.西北)[anchor =西南,内部sep = 0mm,xshift = 8.3mm,yshift = -8.6mm] {\ includegraphics [高度= 3.8毫米] {img/my_logo}};\ end {tikzpicture}}\ setbeamertemplate {footline} {}\ begin {frame} [noframenumbering]\ begin {tikzpicture}\useasboundingbox (0,0) 矩形(\the\paperwidth,\the\paperheight);\ node [shift = {(-11.5mm,-1.8mm)},fill = titlefgcolor!50!white,最小宽度= 0.46 \ paperwidth,最小高度= 18mm,锚=西,内部隔垫= 4mm],位于(当前page.west){\ hspace * {9mm}\ begin {minipage} {\ titleboxwidth}\ rackright\ usebeamerfont {title} \ usebeamercolor [fg] {title} \ inserttitle \ par\ usebeamerfont {author} \ usebeamercolor [fg] {author} \ insertauthor \ par\ usebeamerfont {date} \ usebeamercolor [fg] {date} \ insertdate\ end {minipage}};\ end {tikzpicture}\ end {frame}}}%TOC帧\ newcommand {\ tocframe} {%\ begin {frame}\ frametitle {概述}\目录\ end {frame}}%部分标题框架\ AtBeginSection []{\ begin {frame}\ frametitle {概述}\大\ tableofcontents [currentsection]\ end {frame}}%框架标题\ setbeamertemplate {frametitle} {\ vspace {2mm}\ insertframetitle \\\ usebeamerfont {framesubtitle} \ insertframesubtitle\ vspace {2.5mm}}足迹百分比\ setbeamertemplate {footline} {\ leavevmode%\ hyperlink {目录---目录} {\ includegraphics [width = 12mm,trim = 0mm 0.4mm 0mm 0mm] {img/my_logo.png}}\ hfill\hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}\ vspace {3mm}}\ mode< all> 

preamble.tex

 %标题"在YAML标头中被注释掉:否则markdown生成第二张标题幻灯片%,如果标题不包含特殊字符:将其直接输入到YAML标头末尾的LaTex中如果标题包含特殊字符(例如:"),则为%,请在此处将其提供给LaTex:\ title [short version] {标题的第一行:\\标题的第二行} 
解决方案

  • 通过markdown插入其他框架,因为即使没有内容实际打印到该框架,它也会自动启动不必要的框架.通过将 \ tocframe 放在 \ titleframe 之后,可以避免标题和toc框架之间的空白.

  • 对于黑框,您可以定义一个新的宏,例如

      \ newcommand {\ blackframe} {{\ setbeamercolor {background canvas} {bg = black} \ begin {frame} [plain] \ end {frame}}} 


  ---副标题:具有R-markdown的光束预视"研究所:某处"日期:`r format(Sys.time(),'%​​B%d,%Y')`";作者:唐老鸭"输出:#beamer_presentation:默认bookdown :: pdf_book:base_format:rmarkdown :: beamer_presentation#包括:#in_header:preamble.tex主题:"THEMENAME";latex_engine:xelatex目录:假slide_level:2keep_tex:是标头包括:-\ newcommand {\ blackframe} {{\ setbeamercolor {background canvas} {bg = black} \ begin {frame} [plain] \ end {frame}}}-\ AtBeginDocument {\ title {MWE} \ titleframe \ blackframe \ tocframe}-\ AtEndDocument {\ begin {closingframe} lalala \ end {closingframe}}-\ makeatletter \ beamer @ ignorenonframefalse \ makeatother---```{r setup,include = FALSE}knitr :: opts_chunk $ set(echo = FALSE)```# 部分##带子弹滑<!-=======================================================--子弹1-第2弹-子弹3```{=乳胶}\ end {frame}\ blackframe\ begin {frame}```<!-附录-><!-=======================================================-```{=乳胶}\ end {frame}\附录\ begin {frame}``` 

I use a custom LaTex beamer theme in an rmarkdown::beamer_presentation.As per these SO answers (LaTex theme, colon, theme path), I used several modifications of the YAML header and beamerthemeTHEMENAME.sty.These LaTex hacks are necessary to apply the LaTex Beamer theme smoothly in the rmarkdown::beamer_presentation.

However, currently, a blank slide is inserted by LaTex before and after the table of contents (ToC) slide (see fig 1 below).

  • How can I get rid of these slides?
  • Instead, I would ideally have a completely black slide before the ToC and at other instances during the presentation (i.e., to briefly interrupt and "switch off" the presentation in between)

Note: if I use the option toc: true to generate the ToC (instead of using the \tocframedefined in beamerouterthemeTHEMENAME.sty), markdown messes up the vertical alignment of the ToC and it comes without any headline (see fig 2 below).

Fig 1: using Tocframe from LaTex Template to generate ToC (toc:false in YAML header)

Fig 2: using toc:true in YAML header to generate ToC

MWE.Rmd

---
# COMMENT out "title" in YAML header: else markdown generates a second title slide
# ==> 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 # use LaTex TOC (else vertical alignment is messed up and not headline)
    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

\mode<presentation>

% Tizk, textpos, graphics
\RequirePackage{tikz}
\RequirePackage{textpos}
\RequirePackage{booktabs}

% Beamer settings
\input{beamer_files/beamercolorthemeTHEMENAME.sty}
\input{beamer_files/beamerouterthemeTHEMENAME.sty}

\setbeamertemplate{navigation symbols}{}

\mode<all>

beamerouterthemeTHEMENAME.sty

\mode<presentation>

% Redefine \insertshortinstitute to allow multiple lines
\makeatletter
\renewcommand{\insertshortinstitute}{\beamer@shortinstitute}
\makeatother

% Title frame
\def\titlefigure{img/my_bg}
\newlength\titleboxwidth
\setlength{\titleboxwidth}{0.43\textwidth}
\newcommand{\titleframe}{%
    {
        \setbeamertemplate{background}{
            \begin{tikzpicture}
            \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
            \ifx\titlefigure\empty
                \fill[titlebgcolor] (6.3mm,6.4mm) rectangle (\the\paperwidth-8.3mm,\the\paperheight-13mm);
            \else
                \node at (current page.center) [anchor=center,yshift=-3.5mm] {\includegraphics[width=\the\paperwidth-19mm]{\titlefigure}};
            \fi
            \node 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
            }; 
            \node 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}{}
        \begin{frame}[noframenumbering]
            \begin{tikzpicture}
                \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
                \node [
                    shift={(-11.5mm,-1.8mm)},
                    fill=titlefgcolor!50!white,
                    minimum width=0.46\paperwidth,
                    minimum height=18mm,
                    anchor=west,
                    inner sep=4mm
                    ] at (current page.west) {
                        \hspace*{9mm}
                        \begin{minipage}{\titleboxwidth}
                            \raggedright
                            \usebeamerfont{title}\usebeamercolor[fg]{title}\inserttitle\par
                            \usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor\par
                            \usebeamerfont{date}\usebeamercolor[fg]{date}\insertdate
                        \end{minipage}          
                    };
            \end{tikzpicture}
        \end{frame}
    }
}

% TOC frame
\newcommand{\tocframe}{%
    \begin{frame}
      \frametitle{Outline}
      \tableofcontents
    \end{frame}
}

% Section title frame
\AtBeginSection[]
{
    \begin{frame}
      \frametitle{Outline}
      \large
      \tableofcontents[currentsection] 
    \end{frame}
}

% Frame title
\setbeamertemplate{frametitle}{
    \vspace{2mm}
    \insertframetitle \\
    \usebeamerfont{framesubtitle}\insertframesubtitle
    \vspace{2.5mm}
}

% Footline
\setbeamertemplate{footline}{
    \leavevmode%
    \hyperlink{toc---table-of-contents}{\includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{img/my_logo.png}}   
    \hfill
    \hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
    \vspace{3mm}
}

\mode<all>

preamble.tex

% "title" is commented out in YAML header: else markdown generates a second title slide
% 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 to LaTex here:
\title[short version]{First line of the title:\\ second line of the title}
解决方案

  • The additional frames are inserted by markdown because it will automatically start unnecessary frames even if none of the content is actually printed to the frame. You can avoid the empty frame between the title and your toc frame by placing the \tocframe after your \titleframe.

  • for black frames, you can define a new macro, e.g.

    \newcommand{\blackframe}{{\setbeamercolor{background canvas}{bg=black}\begin{frame}[plain]\end{frame}}}
    


---
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:
  - \newcommand{\blackframe}{{\setbeamercolor{background canvas}{bg=black}\begin{frame}[plain]\end{frame}}}
  - \AtBeginDocument{\title{MWE}\titleframe\blackframe\tocframe}    
  - \AtEndDocument{\begin{closingframe}lalala\end{closingframe}}
  - \makeatletter\beamer@ignorenonframefalse\makeatother
---

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

# section

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

- Bullet 1
- Bullet 2
- Bullet 3

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

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

这篇关于在ToC之后删除其他空白幻灯片,并使用自定义的投影仪主题在rmarkdown :: beamer_presentation中插入黑色幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:38