如何在Rmarkdown HTML输出的末尾删除空白

Jos*_*erg 5 html markdown r knitr r-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)
```
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

虽然我没有方便的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
Run Code Online (Sandbox Code Playgroud)

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

---
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)
```
Run Code Online (Sandbox Code Playgroud)

bca*_*ers 13

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

<div class="tocify-extend-page" data-unique="tocify-extend-page" style="height: 0;"></div>
Run Code Online (Sandbox Code Playgroud)

为我工作!


tar*_*leb 2

这似乎是由HTML 输出中包含的tocify脚本引起的。toc_float如果设置为true(或者包含更多选项),则包含该脚本。

添加空白的选项原则上可以通过 tocifyextendOffset选项进行配置。但是,R Markdown 似乎没有公开通过 YAML 设置选项的方法。目前,摆脱它的唯一方法是取消设置toc_float