4

I am trying to get xtable to insert a table into an R markdown pdf document I'm working on. For some reason, I can't even get the examples from the documentation to reproduce. Instead, the output puts each individual cell on a new line. I've included a screen shot of a portion of my pdf. What am I doing wrong?? Do I need to update a package somewhere? I downloaded xTable today.

```{r, echo=FALSE, results = "asis"}
library(xtable)
data(tli)
print(xtable(tli[1:10,]), type = "html", floating = FALSE, include.rownames = T)
```

Sample of bad pdf

Sample of bad pdf

Waylan
  • 37,164
  • 12
  • 83
  • 109
  • 3
    you should be using `type = "latex"` or leave out `type` entirely since the default is latex.. does that give what you want? – rawr Dec 12 '17 at 22:42
  • @rawr is right - as a side note, if you want table output that's automatically in the same format as your RMarkdown document output, you can use `knitr::kable`. It isn't as pretty, but it saves you from having to specify types or remembering to use the `results = "asis"' argument. – Sean Norton Dec 13 '17 at 01:58
  • If you use `knitr::kable`, you can add relatively complex formatting without too much pain by using the [`kableExtra` package](http://haozhu233.github.io/kableExtra/). – eipi10 Dec 13 '17 at 02:01
  • Oh, thank goodness! Leaving type out worked! I needed more customization than kable offered for the tables I intended to generate. – Meghan Franklin Dec 13 '17 at 13:50
  • @MeghanFranklin try the [htmlTable](https://github.com/gforge/htmlTable) package then. it is very customizable and was designed to mimic xtable, so you might be familiar with the syntax already – rawr Dec 14 '17 at 22:13

0 Answers0