减少rmarkdown投影仪演示中的代码块和代码输出之间的空间 [英] Reduce space between code chunks and code output in rmarkdown beamer presentation
问题描述
我正在使用rmarkdown和LaTeX/Beamer构建演示文稿.我想减小显示的R命令和R输出之间的间距.我认为这与LaTeX/Beamer中的段落间距选项有关.
I'm building a presentation using rmarkdown and LaTeX/Beamer. I would like to reduce the spacing between the displayed R-commands and R-output. I believe this is related to the paragraph spacing options in LaTeX/Beamer.
这是我应该在rmarkdown(块选项,knit_hooks或其他选项),pandoc Yaml标头(某些pandoc选项吗)还是LaTeX Beamer模板文件中执行的操作吗?我觉得它应该在LaTeX模板文件中.
Is this something I should do in rmarkdown (chunk options, knit_hooks, or something else?), in the pandoc Yaml header (some pandoc option?), or in the LaTeX beamer template file? I feel like it should be in the LaTeX template file.
以下是最小减价文件和一个用于控制某些投影仪设置的.tex模板文件的工作示例.
Below is a working example of a minimal markdown file, and a .tex template file I'm using to control some beamer settings.
示例.Rmd
---
title: "Untitled"
author: "Ryan"
date: "March 1, 2016"
output:
beamer_presentation:
pandoc_args: '--latex-engine=xelatex'
includes:
in_header: latex-topmatter.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Vertical Spacing is too much
Here is a working example.
- some
- bullets
Example code:
```{r, echo = TRUE}
a <- 1
a
a+a
```
latex-topmatter.tex
% declare overall beamer theme to use as baseline
\usetheme{default}
% make code-output smaller
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{fontsize=\tiny,commandchars=\\\{\}}
% make console-output smaller:
\makeatletter
\def\verbatim{\tiny\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
\makeatother
% set vertical spacing between paragraphs:
% \parskip{0pt}
% \addtobeamertemplate{blocks}{}{\setlength{\parskip}{0pt}}
% \addtobeamertemplate{block begin}{}{\setlength{\parskip}{0pt}}
% \addtobeamertemplate{block end}{}{\setlength{\parskip}{0pt}}
% % \setlength{\emergencystretch}{0em}
\setlength{\parskip}{0pt}
我尝试过缩小R命令或R输出的字体,这似乎并不影响段落间距.
I've tried making the font of the R-commands or R-output smaller, which does not seem to affect the paragraph spacing.
在此示例中,我尝试使用knit_hooks()
:
https://github.com/ramnathv/slidify/issues/189 多数有效-但是我似乎无法减小代码和输出的字体大小.
I've tried using knit_hooks()
as in this example:
https://github.com/ramnathv/slidify/issues/189, which mostly works - but then i can't seem to reduce the fontsize of the code and output.
我也尝试过使用\parskip{0pt}
和其他几个投影仪选项或parskip选项,这些在上面的latex-topmatter.tex
部分中进行了注释.它们似乎都没有改变文本,R代码或R输出块之间的间距.我什至在找对地方了吗?
I've also tried using \parskip{0pt}
, and several other beamer options or parskip options, which are commented in the above latex-topmatter.tex
section. None of them seem to change the spacing between chunks of text, R-code, or R-output. Am I even looking in the right place?
推荐答案
这是一个有效的示例.注意头文件末尾的定义:
Here is a working example. Notice the definitions at the end of the header file:
- 源代码块包含在
Shaded
环境中,该环境又使用\OuterFrameSep
为其间隔.因此,我们需要重新定义. - 使用
\preto
,我们在每个逐字环境中添加命令\topsep=-10pt \partopsep=-10pt
.这会影响输出块的间距.
- Source code chunks are contained inside a
Shaded
environment which in turn uses\OuterFrameSep
for its spacing. So we need to redefine that. - With
\preto
we prepend the commands\topsep=-10pt \partopsep=-10pt
to every verbatim environment. This affects the spacing of output chunks.
示例.Rmd
---
title: "Untitled"
author: "Martin"
date: "January 4, 2017"
output:
beamer_presentation:
keep_tex: yes
pandoc_args: --latex-engine=xelatex
includes:
in_header: latex-topmatter.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Vertical Spacing is just right
Here is a working example.
- some
- bullets
Example code:
```{r, echo = TRUE}
a <- 1
a
a+a
```
latex_topmatter.tex
% declare overall beamer theme to use as baseline
\usetheme{default}
% make code-output smaller
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{fontsize=\tiny,commandchars=\\\{\}}
% make console-output smaller:
\makeatletter
\def\verbatim{\tiny\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
\makeatother
\setlength{\parskip}{0pt}
\setlength{\OuterFrameSep}{-4pt}
\makeatletter
\preto{\@verbatim}{\topsep=-10pt \partopsep=-10pt }
\makeatother
这篇关于减少rmarkdown投影仪演示中的代码块和代码输出之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!