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

时间:2018-10-22 16:02:20

标签: html r markdown r-markdown knitr

降价结束时是否有常见的空白原因?这是我的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)
```

2 个答案:

答案 0 :(得分:3)

根据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>

为我工作!

答案 1 :(得分:1)

这似乎是由HTML输出中包含的tocify脚本引起的。如果const o1 = {v: 1}; const o2 = {v: 2}; const m = new Map(); m.set(o1, 'o1'); m.set(o2, 'o2'); m.get(o1) // Time complexity O(1)? m.get(o2) // Time complexity O(1)? 设置为toc_float(或包含更多选项),则包含该脚本。

添加空白的选项原则上可以通过tocify true选项进行配置。但是,似乎R Markdown并未提供通过YAML设置选项的方法。目前,摆脱它的唯一方法是取消设置extendOffset