Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
```
like image 783
Josh Goldberg Avatar asked Oct 22 '18 16:10

Josh Goldberg


2 Answers

According to https://community.rstudio.com/t/floating-table-of-contents-and-plots-produce-extra-whitespace-at-bottom/12606/8 you can keep toc_float and remove the extra white space by inserting the following html code at the bottom of the .Rmd file:

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

Worked for me!

like image 104
bcarothers Avatar answered Oct 01 '22 07:10

bcarothers


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.

like image 32
tarleb Avatar answered Oct 01 '22 07:10

tarleb