R Position of figures in RMarkdown

Refresh

5 weeks ago

Views

17 time

2

I want to knit an article in RMarkdown but the figures (tables) don't appear at the correct position in the document (pdf).

Here I can show you my problem in the example data. The table should appear after the appendix: Can someone show me how I can solve this problem?

enter image description here

And here is y example code:

---
title: "title"
subtitle: "subtitle"
author: "me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
keywords: "keywords"
output:
pdf_document:
fig_cap: yes
keep_tex: yes

documentclass: article
capsize: normalsize
fontsize: 11pt
geometry: margin=1in
spacing: doublespacing
footerdate: yes
abstract: 'Insert abstract here'
---
\newcommand*{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
\keywords{keywords}

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.pos= "h", out.extra = '')
##required packages
library(tidyverse)
library(knitr)
library(kableExtra)
```

# Introduction

# Literature review

# Data and Methodology

# Empirical Results

# Conclusions

\newpage

# References {-}

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

\newpage

# Appendix

```{r echo=F, warning=F, message=F}
df1 <- tibble(column1= 1:10, column2=11:20)

df1%>%kable("latex",
              booktabs=T,
              caption = "Dataframe 1")%>%
kable_styling()
```

1 answers

0

Just add latex_options=c("hold_position") inside kable_stylying:

df1 <- tibble(column1= 1:10, column2=11:20)

df1 %>%
  kable("latex", booktabs=T, caption = "Dataframe 1") %>%
  kable_styling(latex_options = c("hold_position"))