r - 附录当前给我一个只有标题的空白页 - R Markdown

标签 r r-markdown kable landscape-portrait

我试图将表格放在 R Markdown 附录的第一页中,如下所示:

\newpage
# References {-}

<div id="refs"></div>

\newpage
# Appendix {-}

\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

```{r pre_table_appendix, message=FALSE, warning=FALSE, echo=FALSE, include=FALSE, fig.pos="H"}
tab <- matrix(c("text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4"), ncol=4, byrow=TRUE)
colnames(tab) <- c('Variable','Variable','Variable','Variable')
rownames(tab) <- NULL
tab <- as.table(tab)

table_appendix <- kbl(tab, longtable = T, booktabs = T, row.names = 0, caption = "Title.") %>%
kable_styling(latex_options = c("repeat_header"))

```

\begin{landscape}
```{r table_appendix_f, echo=FALSE}
table_appendix
```
\end{landscape}

但是,因为我的 table_appendix 是横向的,所以我最终得到一个空白页,其中只有“附录”,然后另一页包含实际的表格。有人知道如何将表格与附录放在一起吗?

最佳答案

如果我能正确理解你的话...

添加到我们的标题:

 - \usepackage{pdflscape}
 - \newcommand{\blandscape}{\begin{landscape}}
 - \newcommand{\elandscape}{\end{landscape}}

LaTeX 引擎应该是 pdflatex

问题中的代码:

\newpage
# References {-}

<div id="refs"></div>

\newpage
\blandscape
# Appendix {-}


\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

```{r pre_table_appendix, message=FALSE, warning=FALSE, echo=FALSE, include=FALSE, fig.pos="H"}
library(kableExtra)
tab <- matrix(c("text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4",
                "text1", "text2", "text3", "text4"), ncol=4, byrow=TRUE)
colnames(tab) <- c('Variable','Variable','Variable','Variable')
rownames(tab) <- NULL
tab <- as.table(tab)

table_appendix <- kbl(tab, longtable = T, booktabs = T, row.names = 0, caption = "Title.") %>%
kable_styling(latex_options = c("repeat_header"))

```


```{r table_appendix_f, echo=FALSE}
table_appendix
```
\elandscape
\newpage

ccontent 
content
content
content
content

enter image description here

附注关于页码的问题,我想你是知道的。


没有这个问题:

添加到标题:-\usepackage[paper=A4]{typearea}

\newpage
\KOMAoptions{paper=landscape,DIV=current}
\recalctypearea

# Appendix {-}

 *** your code***

```{r table_appendix_f, echo=FALSE}
table_appendix
```
     
\newpage
\KOMAoptions{paper=portrait,DIV=current}
\recalctypearea

ccontent 
content

瞧:)

enter image description here

!!! 但请记住,它会影响您的利润。在打印文档之前更好地检查。

关于r - 附录当前给我一个只有标题的空白页 - R Markdown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69997639/

相关文章:

r - 如何使某些变量的图不可见?

r - 使用 R,将多个卡方列联表测试应用于分组数据框,并添加包含测试 p 值的新列

r - 如何在命令行中复制 Knit HTML?

r - 在 Rmarkdown 的每个部分创建引用

r - 如何手动创建一个简单的表格并用knitr呈现它:kable in R Markdown (more precisely: in Bookdown)?

r - 如何识别输出低于某个阈值的两个变量的哪些组合?

r - 我们可以使用 lmer 使用混合模型进行反向消除吗

r - 如何添加标题和换行符?

r - kable 显示 html 代码而不是 html 表

r - 如何在 rmarkdown 中交叉引用表格和图表?