当将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}}