I am trying to put a table in the first page of the appendix in R Markdown as per:
\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}
However because my table_appendix is in landscape I end up with one blank page with just "Appendix" and then another page with the actual table. Anyone knows how to put the table together with Appendix?
If I have right understand you...
Adding to our header:
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
LaTeX-engine should be pdflatex
.
Your code from the question:
\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
P.S. About this problem with the page's number, you know, I think.
Without this problem:
add to your header: - \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
And voila :)
!!! But remember, it has an influence to your margins. Check better before printing a document.