I've been experimenting recently with the fantastic Sweave/xtable combination for generating latex. In the xtable vignette, I found this great example of printing a ts object by months. Is there a way to modify this code to generate RED numbers inside xtable for negative results in x.ts? Thanks in advance. - Ken # Sweave/xtable snippet below -------------------------------------------------------------- \begin{table}[ht] <<sample,echo=F,results=tex>>x.ts <- ts(rnorm(100), start = c(1954, 7), frequency = 12) x.table <- xtable( x.ts, digits = 1 ) print( x.table, floating = FALSE ) @ \end{table} -- View this message in context: http://www.nabble.com/xtable-formatting%3A-RED-for-negative-numbers--tp24712197p24712197.html Sent from the R devel mailing list archive at Nabble.com.
Ken-JP wrote:> > Is there a way to modify this code to generate RED numbers inside xtable > for > negative results in x.ts? >This post would probably have been better for R-help. Anyway, you can do it easily by modifying print.xtable.R in the xtable package. If it is easier, make a copy of that file, modify it, load the xtable package, then source your modified version. Basically change line 227 from result[i] <- gsub("-","$-$",result[i],fixed=TRUE) to result[i] <- gsub("-","\\color{red}$-$",result[i],fixed=TRUE) and then your code chunk becomes: <<sample,echo=F,results=tex>>= library(xtable) x.ts <- ts(rnorm(100), start = c(1954, 7), frequency = 12) x.table <- xtable( x.ts, digits = 1 ) print( x.table, floating = FALSE, math.style.negative = TRUE) @ Here is the patch: http://www.nabble.com/file/p24726982/print.xtable.R.diff print.xtable.R.diff Here is the output I got: http://www.nabble.com/file/p24726982/xtable-red.pdf xtable-red.pdf - Cameron P.S. You must use the color package in latex. -- View this message in context: http://www.nabble.com/xtable-formatting%3A-RED-for-negative-numbers--tp24715905p24726982.html Sent from the R devel mailing list archive at Nabble.com.
The links to those previous files were broken, here they are: Here is the patch: http://www.nabble.com/file/p24727010/print.xtable.R.diff print.xtable.R.diff Here is the output I got: http://www.nabble.com/file/p24727010/xtable-red.pdf xtable-red.pdf -- View this message in context: http://www.nabble.com/xtable-formatting%3A-RED-for-negative-numbers--tp24715905p24727010.html Sent from the R devel mailing list archive at Nabble.com.