Last active
February 2, 2018 19:34
-
-
Save ivyleavedtoadflax/275294b97f4237142a56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Xtable examples" | |
subtitle: "From [this thread](http://stackoverflow.com/questions/32005471/simple-example-of-using-tables-knitr-for-latex)" | |
author: "Matthew Upson" | |
date: "15 August 2015" | |
output: pdf_document | |
--- | |
```{r} | |
library("xtable") | |
df <- data.frame(matrix(1:50, nrow = 10)) | |
``` | |
```{r xtable, results = "asis"} | |
print( | |
xtable(df), | |
include.rownames = FALSE, | |
include.colnames = FALSE, | |
sanitize.colnames.function = identity, | |
add.to.row = list( | |
pos = list(0), | |
command = c( | |
"& \\multicolumn{4}{c}{$y=a+bx$} \\\\ | |
\\cline{2-5} | |
col1 & col2 & col3 & col4 & col5 \\\\ " | |
) | |
) | |
) | |
``` | |
```{r xtable1, results = "asis"} | |
print( | |
xtable(df), | |
include.rownames = FALSE, | |
include.colnames = FALSE, | |
sanitize.colnames.function = identity, | |
hline.after = c(-1,0), | |
add.to.row = list( | |
pos = list(0,5,10), | |
command = c( | |
"& \\multicolumn{4}{c}{$y=a+bx$} \\\\ | |
\\cline{2-5} | |
col1 & col2 & col3 & col4 & col5 \\\\ ", | |
"\\hline \\multicolumn{5}{l}{Separator in table.} \\\\ \\hline", | |
"\\hline \\multicolumn{5}{l}{Notes at end of table.} \\\\ " | |
) | |
) | |
) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment