使用调用 xtable 的输出将所有列标题加粗的最简单方法是什么,最好是在 print.xtable 命令下。我正在使用 knitr。
答案1
\documentclass[a5paper]{article}
\usepackage{booktabs,colortbl,xcolor}
\begin{document}
A simple raw \texttt{xtable}:
<<before,results='asis',echo=F>>=
library(xtable)
df <- data.frame(
One=c(101.000,22.345),
Two=c(3.45,74.34),
Three=c(65,6.1234))
print(xtable(df))
@
The same table with some formatting:
<<after,results='asis', echo=F>>=
bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
gray <- function(x) {paste('{\\textcolor{gray}{',x,'}}', sep ='')}
print(xtable(df,digits=0),
sanitize.rownames.function=gray,
sanitize.colnames.function=bold,
booktabs=T)
@
\end{document}