Inserting a page break within a code chunk in rmarkdown (converting to pdf)

后端 未结 2 1334
滥情空心
滥情空心 2021-02-05 08:03

I am using rmarkdown, pandoc and knitr to create a pdf including chunks of r code. Within a code chunk I have a for loop which prints a number of graphs and some statistical out

2条回答
  •  独厮守ぢ
    2021-02-05 08:46

    How to insert a page break within an Rstudio .Rmd code chunk that survives conversion to PDF:

    If the \newpage and \pagebreak latex macros aren't working for you, here's a workaround using HTML.

    For example:

    ---
    title: "The Rent"
    output:
      pdf_document: default
      html_document: default
    ---
    
    # This is pre-chunk text.
    
    ```{r, echo=FALSE, results='asis'}
    print("Now we're inside the chunk, using the power of HTML.


    !") print("As you can see from the following diagram") cat("\n") print("The rent...
    ") print(plot(1:10)) print("

    ") #forced new-page happens here. print("

    Is too damned high!!

    ") writeLines("\n") print("Finished") cat("\n\n") ``` This is post chunk text.

    Produces this for me:

    The key ingredients is the print("

    ") and the {r, echo=FALSE, results='asis'} in the chunk header.

提交回复
热议问题