首页 > 解决方案 > Knitr - 更改图表中段落之间的空格失败

问题描述

我想减少我的 Rnw 文件(LateX+R+Knitr)中块之间的空间。我遇到了以下适用于文本输出的 Rnw 文件:https ://gist.github.com/yihui/2760395#file-knitrout-parskip-rnw 。如果您有图表,则没有 - 图表向上移动太远,代码和图表重叠。是否有可能重新定义 knitrout 以影响输出文本而不是图表?我不知道如何附加 pdf 输出,但下面是代码。

\documentclass{article}

% change the space between paragraphs in chunks

\ifdefined\knitrout
  \renewenvironment{knitrout}{
    \setlength{\parskip}{-1in}
  }{
    \setlength{\parskip}{0in}
  }
\else
\fi

\begin{document}

The quick brown fox jumps over the lazy dog the quick brown fox jumps over the
lazy dog the quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog the quick brown fox jumps over the
lazy dog the quick brown fox jumps over the lazy dog.

<<test>>=
set.seed(77)
1+1
(x <- rnorm(30))
@

The quick brown fox jumps over the lazy dog the quick brown fox jumps over the
lazy dog the quick brown fox jumps over the lazy dog.

<<fig.height=3>>=
plot(x)
@
The quick brown fox jumps over the lazy dog the quick brown fox jumps over the
lazy dog the quick brown fox jumps over the lazy dog.

\end{document} 

标签: rlatexknitr

解决方案


最后我在这里找到了解决方案。

\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=-1em \partopsep=-1em }
\makeatother

结果: 在此处输入图像描述


推荐阅读