Maximilian Maximilian - 4 years ago 225
R Question

knitr Markdown LateX like table within HTML document

I would like to produce "LaTeX-like" table within an HTM document using

knitr
markdown (
.Rmd
) through:

knitr::knit2html(input="D:/...Rmd", output="D:/...report.html")


Here is an example. However, if I decided to produce a report, the LaTeX table would be incorrect:

library(xtable)

xtabl <- xtable(head(CO2))
print(xtabl, type="latex", include.rownames=FALSE)


The above gives:

enter image description here

As suggested here is the result. It was NOT a "LaTeX-like" table!

xtabl <- xtable(head(CO2))
print.xtable(xtabl, type="html", include.rownames=FALSE)


enter image description here

EDIT:

What I mean by "LaTeX-like" table is this:

enter image description here

Answer Source

Here's an example of a basic table with htmlTable:

---
title: "Untitled"
author: "Author"
date: "2/5/2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r}
library(htmlTable)
```

```{r, results="asis"}
tab = cbind.data.frame(
  sapply(iris[1:5 , sapply(iris, is.numeric)], function(x) sprintf("%1.1f", x)),
  Species=iris$Species[1:5]
  )

htmlTable(tab, rnames=FALSE, align="rrrrr", align.header="rrrrr",
          css.cell = c(rep("padding-left: 5em", 4), "padding-left: 2em"))
```

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download