R Markdown投影仪演示中的更改背景

问题描述 投票:0回答:1

我正在用rmarkdown编写投影仪演示,我有两种类型的框架,它们的背景应有所不同。所以我在乳胶中写了两个这样的函数:

\newcommand{\settitlestyle}{
\setbeamertemplate{background canvas}{%
  \includegraphics[width = \paperwidth, height = \paperheight] 
{backgroundtitle.jpg}}
} 

\setmainstyle是完全相同的命令,但另一个是jpg。

在YAML中,我已经输入了一个定义功能并调用\settitlestyle的tex文件。作品。但是在第一张幻灯片之后,我想切换到mainstyle。当我在markdown文件中调用\setmainstyle时,没有任何反应。

r latex r-markdown beamer
1个回答
0
投票

\setmainstyle命令的问题是它将在框架内使用,因此无效。

为避免此问题,您可以使用与https://tex.stackexchange.com/questions/173201/beamer-template-with-different-style-options-for-frames中相同的策略来创建将更改背景的框架选项。

不幸的是,rmarkdown只是忽略用户创建的框架选项,而只传递一小部分预定义的选项。为了欺骗rmarkdown,可以重新使用通常不被投影机使用的帧选项,standout帧选项(仅用于都市主题)

---
output: 
  beamer_presentation:
    keep_tex: true
    includes:
      in_header: preamble.tex
---

# frametitle 

test

# frametitle with different background {.standout}

test

# frametitle

test

和preamble.tex

\usepackage{etoolbox}

\defbeamertemplate{background canvas}{mydefault}{%
  \includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}
}
\defbeamertemplate{background canvas}{standout}{%
  \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}
}

\BeforeBeginEnvironment{frame}{%
  \setbeamertemplate{background canvas}[mydefault]%
}

\makeatletter
\define@key{beamerframe}{standout}[true]{%
  \setbeamertemplate{background canvas}[standout]%
}
\makeatother

enter image description here

或者如果您想更改以下所有帧的背景:

\usepackage{etoolbox}

\defbeamertemplate{background canvas}{mydefault}{%
  \includegraphics[height=\paperheight,page=2]{example-image-duck}
}
\defbeamertemplate{background canvas}{standout}{%
  \includegraphics[height=\paperheight]{example-image-duck}
}

\setbeamertemplate{background canvas}[mydefault]%

\makeatletter
\define@key{beamerframe}{standout}[true]{%
  \setbeamertemplate{background canvas}[standout]%
}
\makeatother

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.