2

按照这个例子,这就是我所拥有的

# iris
This section is about the iris dataset
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(iris[, 1:2]), format = "html") %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```

# mtcars
This section is about the mtcars dataset
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(mtcars[, 1:2]), format = "html") %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```

但是输出看起来像这样:

在此处输入图像描述

如何使mtcars部分出现在iris部分下方?

4

2 回答 2

2

我想kableExtra还没有提供这样的功能。

但是,您可以解析为html,并毫不费力地执行以下操作:

---
title: "hi"
author: "me"
date: "March 23, 2018"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(knitr)
library(kableExtra)
options(knitr.table.format = "html")
```

```{r}
kable(head(iris[, 1:2])) %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# iris
This section is about the iris dataset.

This could be a whole paragraph.
<p style="clear: both"></p>

```{r}
kable(head(mtcars[, 1:2])) %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# mtcars
This section is about the mtcars dataset

相关位是<p style="clear: both"></p>

于 2018-03-23T22:05:13.237 回答
1

将文本放在表格之后,并添加换行符。由于输出是 html,它似乎不知道表格有多大,并使用简单的 HTML 标签来环绕。一种解决方案,将其包装在 100% 宽度的表格中:

<table style="width:100vw">
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(iris[, 1:2]), format = "html") %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# iris
This section is about the iris dataset. 
</table>

<table style="width:100vw">
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(mtcars[, 1:2]), format = "html") %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# mtcars
This section is about the mtcars dataset. 
</table>
于 2018-03-23T22:04:16.070 回答