代码之家  ›  专栏  ›  技术社区  ›  RyanStochastic

减少rmarkdown波束器表示中代码块和代码输出之间的空间

  •  19
  • RyanStochastic  · 技术社区  · 10 年前

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

    这是我应该在rmarkdown中做的事情吗(chunk选项、knit_hooks或其他东西?),在pandoc-Yaml头中(一些pandoc选项?),还是在LaTeX波束器模板文件中?我觉得它应该在LaTeX模板文件中。

    下面是一个最小标记文件的工作示例,以及一个.tex模板文件,我正在使用它来控制一些波束设置。

    例如: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输出的字体变小,这似乎不会影响段落间距。

    我试过用 knit_hooks() 如在该示例中: https://github.com/ramnathv/slidify/issues/189 ,这基本上是有效的,但我似乎无法减少代码和输出的字体大小。

    我也尝试过使用 \parskip{0pt} ,以及其他几个波束器选项或parskip选项,这些选项在上面进行了注释 latex-topmatter.tex 部分它们似乎都没有改变文本块、R代码或R输出之间的间距。我找对地方了吗?

    parskipNotWorking

    1 回复  |  直到 9 年前
        1
  •  13
  •   Martin Schmelzer    9 年前

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

    • 源代码块包含在 Shaded 反过来使用的环境 \OuterFrameSep 其间距。所以我们需要重新定义它。
    • 具有 \preto 我们预先准备了命令 \topsep=-10pt \partopsep=-10pt 每个逐字记录环境。这会影响输出块的间距。

    例如: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_最重要.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
    

    enter image description here

    推荐文章