0

我一直在尝试在 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>
4

1 回答 1

2

不使用 Pander,但了解到在这种情况下 kable 可能会更好。我只需要将块选项更改为results='asis'并使用kable. table.attr我可以通过参数和使用引导表类(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"')
```
于 2016-10-07T17:12:18.390 回答