I am using r markdown to create some stimuli. I intend to output the r markdown as pdf files.
Because there are 24 stimuli, I am using a for loop to loop through the stimuli to create the output.
What I am currently trying to do is I am trying to figure out if it is possible to add add multiple blank lines for pdf output in the for loop.
my current code chunk looks like this
for (row in 1:nrow(D2)){
a = D2%>% select(Prob) %>% slice(row) %>% pull
print(a)
cat(" \n")
print("Please show your work and write your answer below")
cat(" \n")
print("write your answer here")
cat("\n\\newpage\n")
}
The pdf output looks something like:
problem text
Please show your work and write your answer below
write your answer here
but what I am hoping to have is:
problem text
Please show your work and write your answer below
write your answer here
so that there is some blank space after the text.
I have tried to include multiple cat(" \n")
code in the code chunk, but it seems like that is only intended to include one line break and including multiple doesn't increase the amount of blank lines in the output.
I have tried to use the code <br>
or cat(<br>)
but it also isn't working.
I am wondering if there is any suggestion for adding blank lines within a for loop. Thank you in advance
CodePudding user response:
This may be one approach:
Adjust the vertical spacing as required with the Latex vspace function which takes all the usual Latex units.
```{r, results='asis'}
D2 <- data.frame(Prob = paste("Problem", letters[1:3], "..."))
for (i in 1:nrow(D2)){
cat(D2[i, "Prob"])
cat(" \n")
cat("Please show your work and write your answer below")
cat(" \n")
cat("\\vspace{3cm}")
cat(" \n")
cat("write your answer here")
cat("\\newpage ")
}
```