문제

When using knitr with a class like apa6e the code chunks default to double space like rest of the document. This is not desirable.

This could be altered by wrapping with:

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

How can this be done globally rather than wrapping with the tex single space tags?

MWE .Rnw file

\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}
도움이 되었습니까?

해결책

You can redefine knitrout (which is empty by default) to place knitr output in the singlespace environment:

\renewenvironment{knitrout}{\begin{singlespace}}{\end{singlespace}}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top