html - 如何删除 Rmarkdown HTML 输出末尾的空格

标签 html r markdown r-markdown knitr

Markdown 结束时是否存在空白的常见罪魁祸首?这是我的 HTML 输出的结尾。我的选择:

```
{r }
knitr::opts_chunk$set(fig.width=6, fig.asp=.618, fig.align="center",
fig.path='Figs/', warning=FALSE, message=FALSE, cache=TRUE)
```

enter image description here

虽然我手边没有 reprex,但我确实尝试了几次重新运行,发现 YAML 导致了空白,特别是 toc_float: true

date: "`r format(Sys.time(), '%B, %d %Y')`"
output:
  html_document:
    theme: united
    highlight: textmate
    code_folding: show
    toc: true
    toc_float: true
editor_options:
  chunk_output_type: inline
always_allow_html: yes

编辑:这是一个可重现的例子:

---
date: "`r format(Sys.time(), '%B, %d %Y')`"
output:
  html_document:
    theme: united
    highlight: textmate
    code_folding: show
    toc: true
    toc_float: true
editor_options:
  chunk_output_type: inline
always_allow_html: yes
---

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

## 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}
summary(cars)
```

## Including Plots

You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```

最佳答案

根据 https://community.rstudio.com/t/floating-table-of-contents-and-plots-produce-extra-whitespace-at-bottom/12606/8您可以通过在 .Rmd 文件底部插入以下 html 代码来保留 toc_float 并删除多余的空格:

<div class="tocify-extend-page" data-unique="tocify-extend-page" style="height: 0;"></div>

对我有用!

关于html - 如何删除 Rmarkdown HTML 输出末尾的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52933437/

相关文章:

javascript - 使用 Javascript 单击时使动态创建的单元格的内容变为粗体

html - 调整图像大小以填充但不超过浏览器窗口的最优雅方法?

html - 可以使按钮充当超链接或其他类似按钮,但针对另一个框架? (HTML)

r - 为数据表中的每个唯一值仅选择第一个或最后一个值?

r - 在 R 中将时间转换为 'HMS"字符格式

markdown - Pandoc 在 Markdown 期间转义 iframe 到 HTML 转换

asp.net-mvc - 将 Google Analytics 仪表板集成到 MVC Razor View 中?

r - R中的向量列表-提取向量的一个元素

comments - 如何使用 C 类型语法将 markdown 文档嵌入到工作代码中以进行注释?

unicode - i18n/Markdown - Markdown 是否支持国际化?