Reduce space between code chunks and code output in rmarkdown beamer presentation

泪湿孤枕 提交于 2019-12-02 19:20:39

Here is a working example. Notice the definitions at the end of the header file:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!