3
我试图在Latex文档中突出显示R代码,但似乎无法更改代码框内的字体颜色。例如,我认为commentstyle=\color{red}
应该给我评论的红色字体,但评论显示为蓝色或黑色(不能完全说明)。另外,我认为backgroundcolor=\color{white}
应该给我一个白色背景...使用列表修改乳胶文档中R代码的字体颜色
我正在使用knitr和RStudio来编写和编译pdf。下面的例子。
\documentclass{article}
\usepackage{inconsolata}
\usepackage{listings}
\usepackage{xcolor}
\lstset{ %
language=R,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\tiny\color{gray},
stepnumber=1,
numbersep=5pt,
backgroundcolor=\color{white},
showspaces=false,
showstringspaces=false,
showtabs=false,
rulecolor=\color{black},
tabsize=2,
captionpos=b,
breaklines=true,
breakatwhitespace=false,
title=\lstname,
keywordstyle=\color{blue},
commentstyle=\color{red},
stringstyle=\color{green},
escapeinside={\%*}{*)},
morekeywords={*,...}
}
\begin{document}
This is my document
<<code>>=
render_listings()
# This is a comment
test <- 1 + 1
@
\end{document}
是这样的:
看来knitr使用[Sweavel.sty](http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SweaveTemplate/Sweavel.sty),它定义了一个新环境的自己的配色方案' Rinput'。 – baptiste