0

I'm trying to generate blank lines within a loop containing an H2 header and a table created by the gt package.

In the first example outside the loop we can see that "", the bar followed by two spaces produces the desired effect, but how to achieve this same effect in a loop?

---
title: "Report"

output:
  html_document: default

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r, include=FALSE}
#bibliotecas usadas
library(tidyverse)
library(gt)
```

## Header 1
\  
\  
\
\
4 lines breaks above
\  
\  
```{r gt1, echo=FALSE}

   head(mtcars) %>% gt()
```
\  
\  
```{r gtfor, echo = FALSE, warning=FALSE, message= FALSE, results='asis'}
for( i in 1:3)
{
  cat("\n\n## some Header ##\n")
  
  print("\n\n")
  
  print("\  ")
  
  print(
      head(mtcars) %>% gt()
  )
}
   
jcarlos
  • 425
  • 7
  • 17

1 Answers1

0

I gave up on finding a special command to create new lines and decided to look for the solution by editing the CSS style.

I got the visual result I expected with the use of style recommendations coming from this article "CSS Baseline: The Good, The Bad And The Ugly" in the way below

---
title: "Report"

output:
  html_document: default

---
<style type="text/css">
h1 {
   font-size: 2.5em; 
   line-height: 1.0em; 
   margin-bottom: 8px;
}

h2 {
   font-size: 2.0em; 
   line-height: 1.0em; 
   margin-bottom: 8px;
}

h3 {
   font-size: 1.5em; 
   line-height: 1.0em; 
   margin-bottom: 8px;
}

p {
   font-size: 1.1em; /* 16px is the default em size */
   line-height: 1.45em; /* = 22px/14px */
   margin-bottom: 8px;
}

</style>



```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r, include=FALSE}
#bibliotecas usadas
library(tidyverse)
library(gt)
```

# Header 1
blah blah blah blah blah blahblah blah blah blah blah blah blah blah blahblah blah blahblah blah blahblah blah blahblah blah blahblah blah blah.

## Header 2
blah blah blah blah blah blahblah blah blah blah blah blah blah blah blahblah blah blahblah blah blahblah blah blahblah blah blahblah blah blah.

### Header 3
blah blah blah blah blah blahblah blah blah blah blah blah blah blah blahblah blah blahblah blah blahblah blah blahblah blah blahblah blah blah.

 
```{r gt1, echo=FALSE}

   head(mtcars) %>% gt()
```
\  
\  
```{r gtfor, echo = FALSE, warning=FALSE, message= FALSE, results='asis'}
for( i in 1:3)
{
  cat("### Some Header H3\n")
  cat("blah blah blah blah blah blahblah blah blah blah blah blah blah blah blahblah blah blahblah blah blahblah blah blahblah blah blahblah blah blah.\n\n")
  
  print(
      head(mtcars) %>% gt()
  )
}
   
```
jcarlos
  • 425
  • 7
  • 17