![使用 xtable (knitr) 建立粗體列標題](https://rvso.com/image/309849/%E4%BD%BF%E7%94%A8%20xtable%20(knitr)%20%E5%BB%BA%E7%AB%8B%E7%B2%97%E9%AB%94%E5%88%97%E6%A8%99%E9%A1%8C.png)
使用呼叫 xtable 的輸出(最好是在 print.xtable 命令下)將所有列標題加粗的最簡單方法是什麼。我正在使用針織物。
答案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}