I writing a Word document with R markdown in R Studio. I can get many things, but at the moment I am not figuring out how can I get a page break. I have found solutions but only for rendered latex / pdf document that it is not my case.
Basically just copy and paste your code into pretty R, and copy and paste the output (not the html) into the open document. Show activity on this post. After you copy from the Rstudio Console window and paste into a Word document, you need to highlight all the the just copied text and change the font into Courier New.
How can I copy the output of the R console into a word document? Select what you want in the console and copy. Then in Word paste using Keep Text Only. (Right click to get the paste options.)
There are three ways to insert a thematic break in Markdown, using three or more asterisks * , hyphens - or underscores _ , possibly with whitespace in between them. They all result in the same HTML (or PDF) output, which can then be used to create page breaks.
In RStudio, click the Knit Word button. A Word document should appear. Save this Word file under a new name (for example, word-styles-reference-01. docx) in the same directory as the R Markdown file.
Added: To insert a page break, please use \newpage
for formats including LaTeX, HTML, Word, and ODT.
https://bookdown.org/yihui/rmarkdown-cookbook/pagebreaks.html
Paragraph before page break. \newpage First paragraph on a new page.
Previously: There is a way by using a fifth-level header block (#####
) and a docx template defined in YAML.
After creating headingfive.docx
in Microsoft Word, you select Modify Style
of the Heading 5
, and then select Page break before
in the Line and Page Breaks
tab and save the headingfive.docx
file.
--- title: 'Making page break using fifth-level header block' output: word_document: reference_docx: headingfive.docx ---
In your Rmd
document, you define reference_docx
in the YAML header, and now you can use the page-breaking #####
.
Please see below.
https://www.r-bloggers.com/r-markdown-how-to-insert-page-breaks-in-a-ms-word-document/
With the help of John MacFarlane and others on the pandoc google group, I put together a filter that does this. Please see: https://groups.google.com/forum/#!topic/pandoc-discuss/FzLrhk0vVbU In short, the filter needs to look for something to replace with the openxml for pagebreak. In this case \newpage
is being replaced with <w:p><w:r><w:br w:type=\"page\"/></w:r></w:p>
This allows for a single latex markup to be interpreted for both pdf and word output. Joel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With