0

I have been trying to use a two-column layout in an Rmarkdown document which include a table rendered using Pander. I would like the table to render to the width of the column but all the options that I have tried do not seem to work. Here is a simple example.

---
title: "Untitled"
output: html_document
---

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

<div class = "row">
<div class = "col-md-6">

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars, fig}
plot(pressure)
```
</div>

<div class = "col-md-6">
## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
library(pander)
pander(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
</div>
</div>
Sr Julien
  • 494
  • 1
  • 8
  • 27
rjss
  • 935
  • 10
  • 23
  • `pander` generates a markdown table, and then `pandoc` converts that to HTML (or any other document format needed) as part of `rmardkdown`. If you want to stretch the table to the full width of the page/column, I think it's rather a CSS (when using HTML) issue -- the markdown table definitions has not much to do with it. – daroczig Oct 07 '16 at 17:54

1 Answers1

2

Not using Pander but learned that kable may be better in this case. I just need to change the chunk option to results='asis' and use kable. I addition formatting of the table can be added easily with the table.attr parameter and use of Bootstrap table classes (http://v4-alpha.getbootstrap.com/content/tables/).

```{r pressure, echo=FALSE, results='asis'}
library(knitr)
#pander(pressure, convert = "html")
kable(pressure, format = "html", table.attr='class="table table-hover"')
```
rjss
  • 935
  • 10
  • 23