Skip to content

Instantly share code, notes, and snippets.

@ivyleavedtoadflax
Last active February 2, 2018 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivyleavedtoadflax/275294b97f4237142a56 to your computer and use it in GitHub Desktop.
Save ivyleavedtoadflax/275294b97f4237142a56 to your computer and use it in GitHub Desktop.
---
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