我一直在尝试在Rmarkdown文档中使用两列布局,其中包括使用Pander渲染的表格。我希望表格呈现为列的宽度,但我尝试的所有选项似乎都不起作用。这是一个简单的例子。
---
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>
答案 0 :(得分:2)
不使用Pander但是在这种情况下我知道kable可能更好。我只需要将chunk选项更改为results='asis'
并使用kable
。我可以使用table.attr
参数和使用Bootstrap表类(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"')
```