Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX Error: \caption outside float when saving a table with caption to PDF #224

Closed
etiennebacher opened this issue Apr 5, 2024 · 2 comments

Comments

@etiennebacher
Copy link

library(tinytable)
library(tinytex)

packageVersion("tinytable")
#> [1] '0.2.1.4'
tinytex::tlmgr_version()
#> tlmgr revision 70671 (2024-03-17 02:10:09 +0100)
#> tlmgr using installation: C:/Users/etienne/AppData/Roaming/TinyTeX
#> TeX Live (https://tug.org/texlive) version 2024

dest <- tempfile(fileext = ".pdf")

### No caption works fine

tt(mtcars) |> 
  save_tt(dest)

### Adding a caption errors

tt(mtcars, caption = "foo") |> 
  save_tt(dest, overwrite = TRUE)
#> ! LaTeX Error: \caption outside float.
#> Error: LaTeX failed to compile idix9jyl0ekzcvee9gaisf.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See idix9jyl0ekzcvee9gaisf.log for more info.
@vincentarelbundock
Copy link
Owner

Thanks for the report.

The root of the issue is that we use the standalone LaTeX package to save a cropped table to file, but that package does not easily seem to accommodate floats with captions.

I need to do an overhaul of captions for all formats (see #208), but it might take me a little while.

@vincentarelbundock
Copy link
Owner

Thanks again for the report. Should be fixed on Github. This code:

library(tinytable)
x <- mtcars[1:5, 1:5]
tt(x, caption = "A simple table with caption.", width = .6) |>
    save_tt("example.pdf", overwrite = TRUE)

Generates this file:

example.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants