【问题标题】:Knitr - change the space between paragraphs in chunks failed for chartsKnitr - 更改图表中段落之间的空间失败
【发布时间】:2018-07-05 08:39:41
【问题描述】:

我想减少我的 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} 

【问题讨论】:

    标签: r latex knitr


    【解决方案1】:

    我终于找到了解决方案here

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

    结果:

    【讨论】:

    • 可以发前后图片吗?在我的系统上看起来就像我没有尝试更改间距一样。
    • 如果您不想在段落之间留出空格(i.e \setlength{\parskip}{\baselineskip},则此方法有效。如果您想在段落之间添加空格,例如\setlength{\parskip}{1em},它不起作用
    【解决方案2】:

    只需使用较小的负数\parskip。例如,这对我来说看起来不错:

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

    结果:

    【讨论】:

    • 谢谢,但遗憾的是没有解决问题。可能可以移动文本,但可以移动数字。
    • 更好的是使用:-0.5em,但即使是那个解决方案也不能让我满意。如果图形和文本在不同的 knitrout 环境中,整个问题就会消失。但是对于一个块,有一个 knitrout。
    猜你喜欢
    • 2017-05-06
    • 1970-01-01
    • 2012-04-09
    • 2014-02-07
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多