在 RMarkdown 中更改块的表示(背景颜色和框架)(使用 Beamer-Presentations)
Change representation (background-color & frame) of chunks in RMarkdown (with Beamer-Presentations)
背景: 我使用的是 metropolis 主题,它的幻灯片背景颜色与 beamer 中块中显示代码的默认背景颜色相同。
问题:我想更改块输出的表示。 source-code & results 应该有不同类型的表示来区分它们。源代码背景应该比 metropolis 幻灯片背景稍微深灰色,结果应该用黑线包围作为框架。
我已经尝试过的: This threat 回答了我关于 HTML 输出的问题(YAML:output: html_document
),但我没有我不知道如何让它在 beamer_presentation
.
中工作
这是我的“最小”工作示例:
---
title: "The Influence of the German Statutory Minimum Wage's Introduction on Individuals' Health"
author: "Simon Ress | Ruhr-Universität Bochum"
institute: "Conference: 56. Jahrestagung der DGSMP, Leipzig, 2021"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
#Define footer:
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
#hide footer on title page:
- |
\makeatletter
\def\ps@titlepage{%
\setbeamertemplate{footline}{}
}
\addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
\makeatother
#show footer on section's start/title pages:
#overwrite "plain,c,noframenumbering" in section pages definition -> enables footer:
- |
\makeatletter
\renewcommand{\metropolis@enablesectionpage}{
\AtBeginSection{
\ifbeamer@inframe
\sectionpage
\else
\frame[c]{\sectionpage}
\fi
}
}
\metropolis@enablesectionpage
\makeatother
#define footer of section pages:
- |
\makeatletter
\def\ps@sectionpage{%
\setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
}
\addtobeamertemplate{section page}{\thispagestyle{sectionpage}}{}
\makeatother
#add secrtion numbers to TOC:
- |
\setbeamertemplate{section in toc}{
\leavevmode%
\inserttocsectionnumber.
\inserttocsection\par%
}
\setbeamertemplate{subsection in toc}{
\leavevmode\leftskip=2.5em\inserttocsubsection\par}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
您可以使用\definecolor{shadecolor}{RGB}{148,248,248}
更改代码的颜色(选择您喜欢的任何颜色)
在输出周围添加一个框架有点麻烦。 rmarkdown 自动加载各种包以格式化逐字代码,如 fancyverb
包,但随后它会继续并忽略它们并使用正常的乳胶 verbatim
endvironment 输出。完全没有意义,但是你可以使用这个肮脏的 hack 来重新定义这样的环境,以使用提供添加框架选项的 fancyverb 包:
\let\verbatim\undefined
\let\verbatimend\undefined
\DefineVerbatimEnvironment{verbatim}{Verbatim}{frame=single}
---
title: "The Influence of the German Statutory Minimum Wage's Introduction on Individuals' Health"
author: "Simon Ress | Ruhr-Universität Bochum"
institute: "Conference: 56. Jahrestagung der DGSMP, Leipzig, 2021"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: yes
latex_engine: xelatex
#theme: metropolis
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
#Define footer:
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
#hide footer on title page:
- |
\makeatletter
\def\ps@titlepage{%
\setbeamertemplate{footline}{}
}
\addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
\makeatother
#show footer on section's start/title pages:
#overwrite "plain,c,noframenumbering" in section pages definition -> enables footer:
- |
\makeatletter
\renewcommand{\metropolis@enablesectionpage}{
\AtBeginSection{
\ifbeamer@inframe
\sectionpage
\else
\frame[c]{\sectionpage}
\fi
}
}
\metropolis@enablesectionpage
\makeatother
#define footer of section pages:
- |
\makeatletter
\def\ps@sectionpage{%
\setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
}
\addtobeamertemplate{section page}{\thispagestyle{sectionpage}}{}
\makeatother
#add secrtion numbers to TOC:
- |
\setbeamertemplate{section in toc}{
\leavevmode%
\inserttocsectionnumber.
\inserttocsection\par%
}
\setbeamertemplate{subsection in toc}{
\leavevmode\leftskip=2.5em\inserttocsubsection\par}
\definecolor{shadecolor}{RGB}{148,248,248}
\let\verbatim\undefined
\let\verbatimend\undefined
\DefineVerbatimEnvironment{verbatim}{Verbatim}{frame=single}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
背景: 我使用的是 metropolis 主题,它的幻灯片背景颜色与 beamer 中块中显示代码的默认背景颜色相同。
问题:我想更改块输出的表示。 source-code & results 应该有不同类型的表示来区分它们。源代码背景应该比 metropolis 幻灯片背景稍微深灰色,结果应该用黑线包围作为框架。
我已经尝试过的: This threat 回答了我关于 HTML 输出的问题(YAML:output: html_document
),但我没有我不知道如何让它在 beamer_presentation
.
这是我的“最小”工作示例:
---
title: "The Influence of the German Statutory Minimum Wage's Introduction on Individuals' Health"
author: "Simon Ress | Ruhr-Universität Bochum"
institute: "Conference: 56. Jahrestagung der DGSMP, Leipzig, 2021"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
#Define footer:
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
#hide footer on title page:
- |
\makeatletter
\def\ps@titlepage{%
\setbeamertemplate{footline}{}
}
\addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
\makeatother
#show footer on section's start/title pages:
#overwrite "plain,c,noframenumbering" in section pages definition -> enables footer:
- |
\makeatletter
\renewcommand{\metropolis@enablesectionpage}{
\AtBeginSection{
\ifbeamer@inframe
\sectionpage
\else
\frame[c]{\sectionpage}
\fi
}
}
\metropolis@enablesectionpage
\makeatother
#define footer of section pages:
- |
\makeatletter
\def\ps@sectionpage{%
\setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
}
\addtobeamertemplate{section page}{\thispagestyle{sectionpage}}{}
\makeatother
#add secrtion numbers to TOC:
- |
\setbeamertemplate{section in toc}{
\leavevmode%
\inserttocsectionnumber.
\inserttocsection\par%
}
\setbeamertemplate{subsection in toc}{
\leavevmode\leftskip=2.5em\inserttocsubsection\par}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
您可以使用
\definecolor{shadecolor}{RGB}{148,248,248}
更改代码的颜色(选择您喜欢的任何颜色)在输出周围添加一个框架有点麻烦。 rmarkdown 自动加载各种包以格式化逐字代码,如
fancyverb
包,但随后它会继续并忽略它们并使用正常的乳胶verbatim
endvironment 输出。完全没有意义,但是你可以使用这个肮脏的 hack 来重新定义这样的环境,以使用提供添加框架选项的 fancyverb 包:\let\verbatim\undefined \let\verbatimend\undefined \DefineVerbatimEnvironment{verbatim}{Verbatim}{frame=single}
---
title: "The Influence of the German Statutory Minimum Wage's Introduction on Individuals' Health"
author: "Simon Ress | Ruhr-Universität Bochum"
institute: "Conference: 56. Jahrestagung der DGSMP, Leipzig, 2021"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: yes
latex_engine: xelatex
#theme: metropolis
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
#Define footer:
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
#hide footer on title page:
- |
\makeatletter
\def\ps@titlepage{%
\setbeamertemplate{footline}{}
}
\addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
\makeatother
#show footer on section's start/title pages:
#overwrite "plain,c,noframenumbering" in section pages definition -> enables footer:
- |
\makeatletter
\renewcommand{\metropolis@enablesectionpage}{
\AtBeginSection{
\ifbeamer@inframe
\sectionpage
\else
\frame[c]{\sectionpage}
\fi
}
}
\metropolis@enablesectionpage
\makeatother
#define footer of section pages:
- |
\makeatletter
\def\ps@sectionpage{%
\setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021 | SIMON RESS}}}
}
\addtobeamertemplate{section page}{\thispagestyle{sectionpage}}{}
\makeatother
#add secrtion numbers to TOC:
- |
\setbeamertemplate{section in toc}{
\leavevmode%
\inserttocsectionnumber.
\inserttocsection\par%
}
\setbeamertemplate{subsection in toc}{
\leavevmode\leftskip=2.5em\inserttocsubsection\par}
\definecolor{shadecolor}{RGB}{148,248,248}
\let\verbatim\undefined
\let\verbatimend\undefined
\DefineVerbatimEnvironment{verbatim}{Verbatim}{frame=single}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```