Search code examples
r-markdownbookdown

I want text between figures but it shows text above figures


I am creating a pdf with bookdown.

My problem is that I have the text between figures but it shows the text above the figures and the figures below one by one.

index.Rmd

--- 
title: "A title"
author: "George"
date: "`r Sys.Date()`"
output:
  bookdown::tufte_book2: default
description: V
documentclass: book
link-citations: yes
bibliography: book.bib
site: bookdown::bookdown_site
biblio-style: apalike
---

02-explore.Rmd

# Explore {#explore}

```{r global, echo=FALSE, include=FALSE}
library(knitr)
knitr::opts_chunk$set(cache = TRUE, warning = FALSE, message = FALSE, tidy = FALSE,
                      fig.width = 6, fig.height = 4, dev = "cairo_pdf")

# list libraries and load data frame
```

Text goes here .

```{r title1, echo = FALSE, fig.cap = "One"}
ggplot
```

Another text .

```{r stw-title2, echo = FALSE, fig.cap = "Two"}
ggplot
```

output.yml

bookdown::tufte_book2:
  includes:
    in_header: preamble.tex
    before_body: dedication.tex
    after_body: after.tex
  latex_engine: xelatex
  citation_package: natbib

So, I want some text , first figure below , another text and another figure below, but instead I am receiving all text above all figures.


Solution

  • I found that if I use :

    fig.width = 5 and fig.aps = 1/2 (or 1/3)
    

    then the text and figures appear in the right order.

    So, it was a problem with fig.height.