Skip to content
Branch: master
Find file Copy path
1 contributor

Users who have contributed to this file

71 lines (52 sloc) 1.49 KB
\title{Demos of tables with \texttt{kable()} in knitr}
\author{Yihui Xie}
<<setup, include=FALSE>>=
# in this document we mainly use results='asis', so set it globally
The function \texttt{kable()} is a simple table generator. Unlike
sophisticated packages (e.g. \textbf{xtable}, which has more than 30
arguments), this function only has a minimal number of arguments to generate
simple tables.
kable(head(iris, 0))
kable(head(iris, 1))
\section{No row names}
kable(head(iris), row.names=FALSE)
\section{At most 3 digits}
kable(matrix(rnorm(20),4), digits=3)
By default, numeric columns are right-aligned, and other columns are
kable(head(iris), align=c('l', 'c', 'r', 'l', 'r'))
\section{Default tables are ugly}
Let's use the \textbf{booktabs} package. The air is suddenly fresh!
kable(head(iris), row.names=FALSE, booktabs=TRUE)
kable(head(iris, 0), row.names=FALSE, booktabs=TRUE)
kable(head(iris, 1), row.names=FALSE, booktabs=TRUE)
kable(head(mtcars[, 1:7]), booktabs=TRUE)
\section{Long tables}
kable(mtcars[, 1:7], longtable=TRUE, booktabs=TRUE)
\section{Want more features?}
No, that is all I have. You should turn to other packages for help. I'm not
going to reinvent their wheels.
You can’t perform that action at this time.