1

I am knitting an Rmd file in RStudio to HTML, and I'd like to increase the space between body text and tables/figures. Here's a nice solution for PDF output. What part of the CSS specifies this spacing in HTML output? I'm looking for a template-wide solution, not a manual <br>.

---
title: "Example"
output: 
  bookdown::html_document2:
    fig_captions: yes
    number_sections: false
    theme: cerulean
    highlight: tango
    toc: true
    code_download: true
    code_folding: "show"
    toc_float: true
---

<style type="text/css">

body{ /* Normal  */
      font-size: 18px;
      font-family: Helvetica;
  }

div#TOC li {
    list-style:none;
    background-image:none;
    background-repeat:none;
    background-position:0;
}
</style>

```{r setup, include=FALSE}
library(ggplot2)
library(knitr)
```

## Section

Here is some text before a table.

```{r cars}
kable(head(cars))
```

Here is some text after the table. Here comes a plot. Could use more space after the table and before the plot.

```{r pressure, echo=FALSE, fig.align="center", fig.cap="My caption", message=FALSE, warning=FALSE}
ggplot(cars, aes(speed)) +
  geom_histogram()
```

Here is some text after the plot. Need some space between the figure caption and the body text.

enter image description here

Eric Green
  • 7,385
  • 11
  • 56
  • 102

1 Answers1

2

Add

.figure {
   margin-top: 100px;
   margin-bottom: 100px;
}

table {
    margin-top: 100px;
    margin-bottom: 100px !important;
}

inside the <style> tag. Obviously adjust to the needed amount.

GGamba
  • 13,140
  • 3
  • 38
  • 47