The booktabs package in latex makes really beautiful tables. This package provide some additional commands to enhance the quality of table in LaTeX, especially if there is math in your table that might run up against the regular \hline
in the tabular environment. I created a table with the following code:
% file: example.Rnw
% require xtable
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[!h]
\centering
\caption{This is my table.}
\label{tab:table1}
<<mytable,echo=F,results=tex>>=
mat <- as.data.frame(matrix(runif(25),nrow=5))
colnames(mat) <- c("$\\alpha$","$\\beta$",
"$\\gamma$","$\\delta$","$\\frac{\\epsilon}{2}$")
rownames(mat) <- c(‘A’,’B’,’C’,’D’,’E’)
mat <- xtable::xtable(mat,digits=rep(5,ncol(mat)+1))
print(mat,
sanitize.text.function =
function(x){x},
floating=FALSE,
hline.after=NULL,
add.to.row=list(pos=list(-1,0,
nrow(mat)), command=c('\\toprule\n',
'\\midrule\n','\\bottomrule\n')))
@
\end{table}
\end{document}
You can use to compile:
$ R CMD Sweave example.Rnw
$ pdflatex example.tex
The definition of \toprule, \midrule and \bottomrule from
booktabs package is:
\def\toprule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\abovetopsep
\global\@belowrulesep=\belowrulesep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}
\def\midrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowrulesep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\lightrulewidth]}}
\def\bottomrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowbottomsep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}