In rmarkdown (in RStudio), I use the htmlTable package to create beautiful tables in my html documents. Now I want to get the same result when rendering a pdf document. Tables are not displayed properly. How can I let rmarkdown generate tables in my pdf as well as in my html?
This is a working example of a .Rmd file with the following table:
---
title: "test"
output: pdf_document
---
```{r results="asis"}
library(htmlTable)
c1 <- c("test1","test1","test2","test2")
c2 <- c(1,2,3,4)
data_object <- as.data.frame(cbind(c1,c2))
names(data_object) <- c("test","test2")
print(htmlTable(data_object))
```
Click the pdf insert in RStudio.
Result in my pdf document:
test
library(htmlTable)
c1 <- c("test1","test1","test2","test2")
c2 <- c(1,2,3,4)
data_object <- as.data.frame(cbind(c1,c2))
names(data_object) <- c("test","test2")
print(htmlTable(data_object))
test
test2
1
1
1
2
1
2
3
2
3
4
2
4
1
The result (parts of the table) should be:

Does anyone have an idea on how to solve this?
source
share