簡體   English   中英

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

[英]Change background in R Markdown beamer presentation

我正在用 rmarkdown 寫一個投影儀演示文稿,我有兩種類型的框架,它們的背景應該有所不同。 所以我在乳膠中寫了兩個這樣的函數:

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

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

在 YAML 中,我已經輸入了一個定義函數並調用\\settitlestyle的 tex 文件。 作品。 但是在第一張幻燈片之后,我想切換到 mainstyle。 當我在 markdownfile 中調用\\setmainstyle時,什么也沒有發生。

您的\\setmainstyle命令的問題在於它將在框架內使用,因此無效。

為避免此問題,您可以使用與https://tex.stackexchange.com/questions/173201/beamer-template-with-different-style-options-for-frames 中相同的策略來創建一個框架選項,該選項將更改背景。

不幸的是 rmarkdown 只是忽略用戶創建的框架選項,只傳遞一小部分預定義選項。 為了欺騙 rmarkdown,可以重新利用一個通常不被 Beamer 使用的框架選項, standout框架選項(它僅被 Metropolis 主題使用)

---
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

在此處輸入圖片說明

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

\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

在此處輸入圖片說明

暫無
暫無

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

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