57

Is there a way to do it by adding latex code in the text or does the solution lie in (R)Markdown?

No sign of a solution here: http://rmarkdown.rstudio.com/pdf_document_format.html

At present I'm bodging a solution by adding my monospace signature to the bottom of the 1st page, to force the next section to start on page 2: https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/intro-spatial-rl.pdf

0

5 Answers 5

47

Another easy way to do this is to just use HTML tags. Adding <br> will give a single line break and I've used that when, for whatever reason, using the (two-space indentation) is ignored.

1
  • 5
    Another fix is putting a backslash `\` just in front of the newline, resulting in a blank line in the html. I also find that two-spaces followed by newline does not work.
    – bdemarest
    Sep 4, 2015 at 21:34
47

To create vertical space (Markdown to PDF), I use &nbsp;

This command works like \vspace{12pt} for latex.

3
  • 1
    Fantastic! This works beautifully. Thank you kindly. Jun 5, 2017 at 19:46
  • 2
    No downvote or anything, just clarify that works for pdf but not html
    – Conner M.
    Oct 29, 2018 at 16:12
  • 1
    what is equivalent of \vspace{-12pt}?
    – Dayne
    Aug 11, 2020 at 19:11
22

You can use latex inside your Rmd file. To have a page break, just add \newpage.

example.Rmd

Title
====================

This is a test Rmd document. 

\newpage

Second page
====================

This text is on the second page

You make a pdf using render("example.Rmd", output_format='pdf_document')

Hope it helps,

alex

1
16

You can also use inline LaTeX to create a 1-inch vertical space like this:

text text text

$$\\[1in]$$

text text text 

Note that you have to leave a blank line before and after the $$\\[1in]$$

4
  • 1
    awesome . . . fyi, this does work in HTML
    – Mike M
    Feb 17, 2021 at 15:49
  • It surely does. It creates a math box full of nothing, but taking up 1 inch of vertical space Apr 23, 2021 at 11:11
  • [WARNING] Could not convert TeX math '\[1in]', rendering as TeX: \[1in] ^ unexpected "[" expecting "%", "\\label", "\\nonumber" or whitespace
    – Magnus
    Aug 3, 2021 at 8:23
  • genius level - the cleanest and simplest solution I've seen yet. No need to learn css, etc...
    – MikeS
    Mar 1 at 21:28
0

\pagebreak can be used the whitespace of an RMarkdown document. Alternatively, cat("\n\n\\pagebreak\n") can be used within an R script.

Example:

Here I insert some text into an RMarkdown document.


  cat("  \n## And here I am demonstrating text within an R script. \n")
  
  cat("  \n### More text. \n")

  cat("  \n### Add page break... \n")
  
  cat("\n\n\\pagebreak\n")

  cat("  \n### Item on new page. \n")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.