rstudio / rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
https://bookdown.org/yihui/rmarkdown-cookbook/
584 stars 225 forks source link

prevent-figures-from-floating error #364

Open MichaelFolkes opened 2 years ago

MichaelFolkes commented 2 years ago

The example https://bookdown.org/yihui/rmarkdown-cookbook/figure-placement.html#prevent-figures-from-floating failed for me with an error: unknown float option 'H' (writing that from memory so wording might be incorrect). However removing the "!" from fig.pos = !H allowed the .rmd to compile

cderv commented 2 years ago

unknown float option 'H'

Did you correctly load the float package as in the example ?

output: 
  pdf_document:
    extra_dependencies: ["float"]

It is common error message (https://fr.overleaf.com/learn/latex/Errors/LaTeX_Error%3A_Unknown_float_option_%60H%27)

jmarshallnz commented 2 years ago

Just confirming that this issue exists, but only when fig.cap is set on a figure.

With fig.pos = "!H" you get the classic "unknown float option 'H'" error. Even with extra_dependices: ["float"] as required.

Changing it to fig.pos="H" results in a clean knit.

This can be reproduced easily with the default .Rmd generated from "New R Markdown" by specifying:

output:
  pdf_document:
    extra_dependencies: ["float"]

and altering the first chunk to be:

knitr::opts_chunk$set(echo = TRUE, fig.cap='foo', fig.pos = "!H", out.extra = "")

Knitting will then produce this error. As @MichaelFolkes suggests, dropping down to fig.pos="H" works.

Presumably it's due to an additional package loaded when figure captions are given which conflicts with the float package.

cderv commented 2 years ago

Thanks for the additional information @jmarshallnz.

I tried to remove some of the packages to find a possible conflict, but without success. Do we have a working example in LaTeX using \begin{figure}[!H] ? I can't seem to make one working with a simple document .tex to compile to .pdf.