One-time code of type knitr when the default value for the default binary space (Rnw)

When using knitr with a class like apa6e , the pieces of code by default have a double space similar to the rest of the document. This is undesirable.

This can be changed by transfer using:

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

How can this be done globally, rather than wrapping tags with a tex tag?

File 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} 
+7
r knitr rnw
source share
1 answer

You can override knitrout (which is empty by default) to put knitr output in singlespace :

 \renewenvironment{knitrout}{\begin{singlespace}}{\end{singlespace}} 
+8
source share

All Articles