vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

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

Closed etiennebacher closed 5 months ago

etiennebacher commented 6 months ago
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 commented 6 months ago

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 https://github.com/vincentarelbundock/tinytable/issues/208), but it might take me a little while.

vincentarelbundock commented 5 months ago

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