我有一个Rmarkdown文档,我想将其编入PDF文档。如何防止代码块结果中的分页。
结果不超过一页。如果将过长的页面剩余结果移动到下一页而不是在第1页上显示表头以及在第2页上显示表的其余部分,那将是明智的。 / p>
很抱歉,如果答案是在某处。我没找到它。
编辑: 请求了一些代码。所以,我们走了。
---
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]
)
```
答案 0 :(得分:1)
我不确定这是否可以自动完成,但可能包括\ newpage或\ pagebreak会强制输出到新页面。
答案 1 :(得分:1)
经过一段时间的解决后再回到这一点。
对我来说可行的只是使用kable()
软件包中的knitr
。这样一来,表格就呈现为一个对象。这是代码:
---
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"))
```