gpt4 book ai didi

r - 类默认双空格时的knitr单空格代码(Rnw)

转载 作者:行者123 更新时间:2023-12-04 11:38:44 25 4
gpt4 key购买 nike

将 knitr 与 apa6e 之类的类一起使用时代码块默认为与文档其余部分一样的双倍空间。这是不可取的。

这可以通过包装来改变:

\begin{singlespace}
<<*>>=
CODE
@
\end{singlespace}

这如何在全局范围内完成,而不是用 tex 单个空格标签包装?

MWE .Rnw 文件
\documentclass[leavefloats]{apa6e}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=apa,backend=biber,bibencoding=latin1]{biblatex}
\DeclareLanguageMapping{american}{american-apa}

\begin{document}

<<setup, include=FALSE, cache=FALSE>>=
# set global chunk options
opts_chunk$set(fig.path='figure/minimal-', fig.align='center', fig.show='hold')
options(replace.assign=TRUE,width=90)
library(ggplot2); library(xtable)
@

\title{MWE}
\shorttitle{MWE}
\author{Tyler Rinker}
\date{\today}
\authornote{\dots}
\abstract{This is an example of an abstract in APA.}
\maketitle


<<foo>>=
x <- "Got me some code"
y <- "look another line"
paste(x, y)
@

\begin{singlespace}
<<bar>>=
x <- "Got me some code"
y <- "look another line"
paste(x, y)
@
\end{singlespace}

\end{document}

最佳答案

您可以重新定义 knitrout (默认为空)将 knitr 输出放在 singlespace环境:

\renewenvironment{knitrout}{\begin{singlespace}}{\end{singlespace}}

关于r - 类默认双空格时的knitr单空格代码(Rnw),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20619678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com