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.
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- >>" markdown 引用语法" href="https://www.manongdao.com/article-2318498.html" > 有没有办法让 markdown-it 支持 ">>>" markdown 引用语法
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
Here is an R script that can be used as a pandoc filter to replace LaTeX breaks (
\pagebreak
) with word breaks, per @JAllen's answer above. With this you don't need to compile a pandoc script. Since you are working in R Markdown I assume one has R available in the system.Save this as
page-break-filter.R
or something like that and make it executable by runningchmod +x page-break-filter.R
in the terminal.Then include this filter the R Markdown YAML like so:
Sungpil's article was close, but didn't quite work. This was the best solution I found for this: https://scriptsandstatistics.wordpress.com/2015/12/18/rmarkdown-how-to-inserts-page-breaks-in-a-ms-word-document/
Even better, the author included the Word template to make this work. The R-blogger's link to his template is broken, and the header is formatted wrong. Some notes I took:
1) You might need to include the whole path to the word template in your Rmd header, like so:
2) The template at the link above changed some of the default style settings so you'll need to change them back
My solution is not very robust but can work for some of us. Assuming you need a page break before each level 1 title in your word document, I defined this in the format template used in the yaml field
reference_docx:
. In this document you modify the Heading 1 format (or equivalent) to insert a page break before the Title. Do not forget to start your template with the first docx rendered with knitr (pandoc) in RStudio.