【问题标题】:Width of Pander table in RmarkdownRmarkdown中Pander表的宽度
【发布时间】:2016-10-07 16:41:36
【问题描述】:

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

【问题讨论】:

  • pander 生成一个降价表,然后pandoc 将其转换为 HTML(或所需的任何其他文档格式)作为rmardkdown 的一部分。如果您想将表格拉伸到页面/列的整个宽度,我认为这是一个 CSS(使用 HTML 时)问题——markdown 表格定义与它没有太大关系。

标签: r r-markdown pander


【解决方案1】:

没有使用 Pander,但了解到 kable 在这种情况下可能会更好。我只需要将块选项更改为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"')
```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多