簡體   English   中英

R Markdown:防止代碼結果中的分頁符

[英]R Markdown: Prevent page break within code results

我有一個 Rmarkdown 文檔,我想將其編入 PDF 文檔中。 如何防止代碼塊結果中的分頁符。

結果不超過一頁。 如果將頁面其余部分太長的結果移到下一頁而不是在第 1 頁上顯示表格標題,而在第 2 頁上顯示表格的其余部分,那將是明智的。

抱歉,如果這個問題的答案就在某個地方。 我沒有找到。

編輯:請求了一些代碼。 所以,我們走了。

---
title: "How to prevent page breaks in R Markdown code results"
author: "Georgery"
date: "10 January 2017"
output: pdf_document
---

# Create
# some
# headlines
# to
# fill
# the
# page
# a
# little
# and
# even
# a 
# little
# more
...and now create some code results
```{r, echo = FALSE}
data.frame(
    a = 1:20
    ,b = letters[1:20]
)
```

我不確定這是否可以自動完成,但可能適當地包含 \\newpage 或 \\pagebreak 會強制輸出到新頁面。

很長一段時間后回到這個問題的解決方案。

對我kable()只是使用knitr包中的kable() 通過這種方式,表格被渲染為一個對象。 這是代碼:

---
title: "How to prevent page breaks in R Markdown code results"
author: "Georgery"
date: "10 January 2017"
output: pdf_document
---

# Create
# some
# headlines
# to
# fill
# the
# page
# a
# little
# and
# even
# a 
# little
# more
...and now create some code results

```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(knitr) # needed to make the table a separate object on only one page
library(kableExtra) # not needed but makes the table nicer
library(tidyverse) # not needed at all, but I like the pipe (%>%)

data.frame(
    a = 1:20
    , b = letters[1:20]) %>%
    kable("latex", booktabs = TRUE) %>% # This already puts it on a separate page
    kable_styling(latex_options = c("striped"))
```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM