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

beamer presentations #244

Closed hjuerges closed 4 months ago

hjuerges commented 4 months ago

Not sure whether this is a tinytable issue.

Style formatting in style_tt() does not work with beamer presentation (at least on my computers). Minimal example below. I checked the tex-files and noted that if formatted as beamer_presentation instead of pdf_document, the table is formatted as "longtable" instead of "table" with "tblr".

---
output: 
  beamer_presentation:
    keep_tex: TRUE
---
library(tinytable)
tt(mtcars[1:4, 1:5]) |> 
  style_tt(
    i=1:2,
    j=3,
    background = "teal",
    color = "white"
  )
vincentarelbundock commented 4 months ago

Thanks for the report. I believe this is due to this upstream bug: https://github.com/rstudio/rmarkdown/issues/2478

It prevents tinytable::usepackage_latex() from adding the proper entries in the LaTeX preable. Here's a workaround.

First, install the development version of tinytable:

library(remotes)
install_github("vincentarelbundock/tinytable")

Second, save this LaTeX code as preamble.tex:

\RequirePackage{tabularray}
\RequirePackage{booktabs}
\RequirePackage{float}
\usepackage[normalem]{ulem}
\usepackage{graphicx}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}

Finally, load the preamble in your YAML header:

---
output: 
  beamer_presentation:
    includes:
      in_header: preamble.tex
---

With these changes, the table appears with colors as expected.

hjuerges commented 4 months ago

Many thanks for the quick response. I wish I could say that your workaround helped, but it didn't, at least on my machine. The tex-file contains the above commands from preamble.tex, but the table environment is still longtable.

vincentarelbundock commented 4 months ago

Did you install the latest from GitHub and restart your R session?

vincentarelbundock commented 4 months ago

Oops wait, looks like I didn't push the commit. I'll let you know when it's done.

vincentarelbundock commented 4 months ago

OK, please try again with version 0.2.1.15

hjuerges commented 4 months ago

Success! Thank you very much. I am glad I can use tinytable now with beamer, because that's where I need it most (for teaching). Best, Hendrik

vincentarelbundock commented 4 months ago

Thanks again for raising this issue. I have added the workaround to the FAQ page.