减少rmarkdown beamer演示中代码块和代码输出之间的空间

时间:2016-03-01 22:05:13

标签: latex r-markdown pandoc spacing beamer

我正在使用rmarkdown和LaTeX / Beamer构建演示文稿。我想减少显示的R命令和R输出之间的间距。我相信这与LaTeX / Beamer中的段落间距选项有关。

这是我应该在rmarkdown(块选项,knit_hooks或其他什么?),pandoc Yaml标题(一些pandoc选项?)或LaTeX beamer模板文件中做的事情?我觉得它应该在LaTeX模板文件中。

下面是一个最小markdown文件的工作示例,以及我用来控制某些beamer设置的.tex模板文件。

example.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
```

胶乳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输出的字体设置得更小,这似乎不会影响段落间距。

我已尝试使用此示例中的knit_hooks()https://github.com/ramnathv/slidify/issues/189,它主要起作用 - 但我似乎无法减少代码和输出的字体大小。

我还尝试使用\parskip{0pt}以及其他一些beamer选项或parskip选项,这些选项在上面的latex-topmatter.tex部分中进行了评论。它们似乎都没有改变文本块,R代码或R输出之间的间距。我是否在寻找合适的地方?

parskipNotWorking

1 个答案:

答案 0 :(得分:8)

这是一个工作示例。请注意头文件末尾的定义:

  • 源代码块包含在Shaded环境中,而\OuterFrameSep环境又使用\preto作为其间距。所以我们需要重新定义它。
  • 使用\topsep=-10pt \partopsep=-10pt,我们将命令--- 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 ``` 添加到每个逐字环境中。这会影响输出块的间距。

<强> example.Rmd

% 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

<强> latex_topmatter.tex

#keyPath

enter image description here

相关问题