0
votes

I am trying to write my master's thesis in RMarkdown.

I first tried to fix an issue with the position of my figures in the pdf document, and used this method : https://stackoverflow.com/a/33801326. So my YAML header looked like this :

title: "example"
author: "me"
output:
  rmarkdown::pdf_document:
    fig_caption: yes        
    includes:  
      in_header: preamble-latex.tex

Then, I wanted my figures numbered and easily cross-referenced. I tried changing the output to bookdown::pdf_document2: since the method I was taught (that is ![caption\label{mylabel}] and \autoref{mylabel} ) did not work at all and ended up with this :

---
title: "example"
author: "me"
output:
  bookdown::pdf_document2:
    fig_caption: yes        
    includes:  
      in_header: preamble-latex.tex
---
```{r label, echo=FALSE, fig.cap="caption", out.width='75%', out.height='75%'}
knitr::include_graphics("../../images/my_image.png")
\```

and tried to cross-reference like this : @ref(fig:label)

The image does appear in the right place, at the right size and with my caption. But it is not numbered (there is no "Figure 1" mention before my caption) and the reference appears almost exactly as is in the knitted document, only without the backslash (so @ref(fig:label)). No matter where I look or what I do, I cannot seem to change that...

Could it be that bookdown's automatic numbering does not work because of the changes I made in the YAML header to keep my images in the right place? What can I do to fix this issue?

1

1 Answers

1
votes

Problem has been solved by

  1. giving up on using bookdown and coming back to the recommended output (that is ::rmarkdown:pdf_document: )
  2. updating all R and tinytex packages
  3. adding a line in the LaTex file :

    /usepackage{float}

to fix an newly appeared error (unknown float option h)

The figures were then held in the right spot and numbered (although they weren't numbered before...)

  1. using \autoref{fig:label} instead of \@ref(fig:label) for the cross-reference, in conjunction with include_graphics()