# Sweave R code chunk default colors in vignette

Typically, if I create a .Rnw file and add R code chunks to it, and then convert it to .pdf file, the R code text will have default color and font than the rest of the document text. An example follows (say it is called "exampleRnw.Rnw"):

\documentclass{article}
\usepackage{float, hyperref}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}

\usepackage{sectsty}
\sectionfont{\fontsize{12}{13}\selectfont}

\begin{document}

<<options, echo=FALSE, warning=FALSE>>=
concordance=TRUE
)
options(width=40)
@

<<label=R options,echo=FALSE>>=
options(width = 60)
options(SweaveHooks = list(fig = function() par(mar=c(3,3,1,0.5),mgp = c(2,1,0))))
@

%\SweaveOpts{prefix.string=fig,include=F,keep.source=T,eps=FALSE}

% <<echo=false>>=
% options(continue="  ")
% @
% %@% TO ELIMINATE THE "+" IN CONSECUTIVE SCRIPT LINES

\title{My title will be here}
\author{My author list will be here}

\tableofcontents

\section{Introduction}

I will write my introduction here.

\subsection{Background}

Here is some background.

\subsection{Code}

Here is some code.

<<>>=
setwd("/Users/")

var1 = 3
var2 = var1 + 5
@

\section{Conclusions}

I will write my conclusions here

\end{document}


To run the code above, I simply used devtools build_vignettes("exampleVignette.Rnw"). You can see in the image below that the R code does not have the nice coloring and font as in the exampleRnw.Rnw file above.

Is it possible for me to use the same color and font in the R code of my vignette with what is used in the R code of the typical .Rnw files?

• Dear @yihui-xie, and using knitr as the engine, how can the default colours for code chunks be changed in a .Rnw file? Thank you very much