How to remove white space at the end of an Rmarkdown HTML output

Viewed 3476

Is there a common culprit for white space at the end of a markdown? Here's what the end of my HTML output looks like. And my options:

```
{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

While I do not have a reprex handy, I did try several reruns, and found that the YAML is causing the white space, specifically the 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

Edit: Here's a reproducible example:

---
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 Answers

This seems to be caused by the tocify script included in HTML output. The script is included if toc_float is set to true (or if it contains more options).

The option to add the white space is configurable in principle through the tocify extendOffset option. However, it appears that R Markdown does not expose a way to set the option through YAML. Currently, the only way to get rid of it is to unset toc_float.

Related