Rmarkdown table 当它可以装进一页时被推到两页
Rmarkdown table pushed to two pages when it can fit in one
我正在尝试为不同的 table 创建单独的 Rmd 文件,其中每个 table 都呈现为单独的 pdf。由于一些复杂的格式问题,我使用 xtable 来尝试解决这个问题。我有一些 table,我预计它们将填满一个 8.5x11.0 的完整页面,边距为 1 英寸。但是当我呈现它们时,pdf 的第一页是空白的,第二页是完整的、格式正确的 table。我正在寻求帮助以使其正常工作。这是我的最小可行示例...
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r results='asis', echo=FALSE, warning=FALSE, eval=TRUE}
require(xtable)
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
size = "normalsize",
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE
)
```
这被保存为 test.Rd
并且我使用...
进行渲染
library(rmarkdown)
render("test.Rmd"
如果我更改页边距大小,似乎只会影响左右页边距。如果我缩小字体的大小,它将适合一页,但我想保持字体大小不变并摆脱空白的第一页。想法?我是一个乳胶新手,很抱歉遗漏了一些明显的东西。
我想如果加上floating = FALSE
这个参数,应该可以解决问题。当您定义 table 时,我认为这是 LaTex
等效于此处的 !h
参数。我还将 library
调用与其他代码分开(并使用 library
而不是 require
),但这是文体和挑剔的。
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r echo=FALSE, warning=FALSE, eval=TRUE, results='hide'}
library(xtable)
```
```{r eval=TRUE, echo=FALSE, results='asis'}
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE,
floating=FALSE
)
```
感谢 ted-dallas 的发帖,我发现 table.placement
选项可以满足我的要求,而无需关闭浮动...
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r results='asis', echo=FALSE, warning=FALSE, eval=TRUE}
require(xtable)
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
size = "normalsize",
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE,
table.placement = "!ht"
)
```
这会生成我正在寻找的输出。
我正在尝试为不同的 table 创建单独的 Rmd 文件,其中每个 table 都呈现为单独的 pdf。由于一些复杂的格式问题,我使用 xtable 来尝试解决这个问题。我有一些 table,我预计它们将填满一个 8.5x11.0 的完整页面,边距为 1 英寸。但是当我呈现它们时,pdf 的第一页是空白的,第二页是完整的、格式正确的 table。我正在寻求帮助以使其正常工作。这是我的最小可行示例...
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r results='asis', echo=FALSE, warning=FALSE, eval=TRUE}
require(xtable)
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
size = "normalsize",
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE
)
```
这被保存为 test.Rd
并且我使用...
library(rmarkdown)
render("test.Rmd"
如果我更改页边距大小,似乎只会影响左右页边距。如果我缩小字体的大小,它将适合一页,但我想保持字体大小不变并摆脱空白的第一页。想法?我是一个乳胶新手,很抱歉遗漏了一些明显的东西。
我想如果加上floating = FALSE
这个参数,应该可以解决问题。当您定义 table 时,我认为这是 LaTex
等效于此处的 !h
参数。我还将 library
调用与其他代码分开(并使用 library
而不是 require
),但这是文体和挑剔的。
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r echo=FALSE, warning=FALSE, eval=TRUE, results='hide'}
library(xtable)
```
```{r eval=TRUE, echo=FALSE, results='asis'}
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE,
floating=FALSE
)
```
感谢 ted-dallas 的发帖,我发现 table.placement
选项可以满足我的要求,而无需关闭浮动...
---
output: pdf_document
tables: true
geometry: margin=1.0in
---
```{r results='asis', echo=FALSE, warning=FALSE, eval=TRUE}
require(xtable)
# set up data frame
df <- data.frame(Label=c(letters[1:26], letters[1:13]), Numbers=1:39)
strCaption <- "\textbf{Supplementary Table 1. This table is just produced with some random data and does not mean anything.}"
# set up xtable output
print(xtable(df, caption = strCaption, label = ""),
size = "normalsize",
include.rownames = FALSE,
include.colnames = TRUE,
caption.placement = "top",
comment=FALSE,
table.placement = "!ht"
)
```
这会生成我正在寻找的输出。