flextable icon indicating copy to clipboard operation
flextable copied to clipboard

Add Beamer to Flextable's Supported Formats?

Open thatchermo opened this issue 3 years ago • 5 comments

I didn't see this feature requested anywhere, so thought I'd suggest it. I noted today that flextable doesn't seem to work with Beamer slides, but does with with PDF output. Since both are LaTeX format, it seems that it might not be too hard to add support for Beamer, although I've often found that "it might not be too hard" is optimistic---there's often a good reason it hasn't been done if it hasn't been done.

In any case, I did find that if I edited the printers.R file to change line 138 from

} else if (grepl("latex", opts_knit$get("rmarkdown.pandoc.to"))) {

to

} else if (grepl("latex|beamer", opts_knit$get("rmarkdown.pandoc.to"))) {`

then I got "mostly" working functionality with format: beamer in Quarto and output: beamer_presentation in R Markdown. I needed to add \usepackage{hhline} by hand to the beginning of the Beamer document. It looks like there might be functionality in Flextable to do that, but I haven't delved that deep yet. I also had an intermittent issue with frames needing to be set as "fragile" in order to compile in xelatex. It didn't happen in my small test examples, but only in my bigger documents, so hard to give a small reproducible example for testing. But, in any case, writing

## New Slide {.fragile}

in the quarto document fixed that problem.

So, I'm very happy that I have a functional solution for myself, as long as I'm willing to add a few tweaks, but thought I'd pass the suggestion along. Thanks for making seemingly the only table package that lets me make a cross-format table with both equations and hlines where I want them!

thatchermo avatar Jul 22 '22 01:07 thatchermo

Hello

I am not sure if I can reproduce your issues. To me, beamer is supported.

To get help, it would be better to follow the guidelines, do you have a reprex? What version are you using? Why did you add to manually add \usepackage{hhline}? (this is supposed to be automatically managed by knitr_print method).

running beamer/rmarkdown

---
output: beamer_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(flextable)
```

## Slide

```{r echo=FALSE}
example_ft <-
  iris |> head() |> 
  flextable() 
example_ft
```


Capture d’écran 2022-07-22 à 19 15 01

running beamer/rmarkdown

---
title: "Untitled"
format: beamer
---


```{r setup, include=FALSE}
library(flextable)
```

## Slide

```{r echo=FALSE}
example_ft <-
  iris |> head() |> 
  flextable() 
example_ft
```

Capture d’écran 2022-07-22 à 19 16 00

I needed to add \usepackage{hhline} by hand to the beginning of the Beamer document. It looks like there might be functionality in Flextable to do that, but I haven't delved that deep yet.

yes, it is flextable::add_latex_dep()

davidgohel avatar Jul 22 '22 17:07 davidgohel

Sorry, I just realised the rmarkdown version was using an image! I can reproduce for the rmarkdown output

davidgohel avatar Jul 22 '22 17:07 davidgohel

Very interesting! I submitted this because I was getting no table output at all in Beamer yesterday. My test file worked in PDF, HTML, PPTX and DOCX, so I assumed Beamer just wasnt supported, especially after seeing "latex", but not "beamer" mentioned explicitly in flextable_to_rmd. Sorry for making the wrong assumption.

Yesterday, I was on someone else's computer, but today on my computer, your code above and my test code from yesterday produce tables as images, which looks like what would be expected. I'll have to see what was up on that other machine, and if I find anything that actually looks like a bug, I'll submit it with a minimal code example.

I could see keeping this as a feature request, since natively-generated tables in Beamer would likely be preferable to images, if there weren't too many obstacles to overcome. If I go further than experimentally changing one line of code, I'll submit the changes back for consideration, but that might be beyond my skill level.

In any case, Thanks!

thatchermo avatar Jul 22 '22 20:07 thatchermo

Let's keep that open and try to support beamer

Your issue on the other computer is probably due to the fact that webshot is not installed.

I may take some weeks before we work on this..

davidgohel avatar Jul 22 '22 20:07 davidgohel

Hi there,

I encountered similar issues when rendering a flextable in a Beamer presentation. Surprisingly, it worked fine for all other document formats like Word, PDF, PPTX, and HTML, except for Beamer. Every attempt to debug the problem was unsuccessful, despite trying the following steps:

  1. Re-installing/Updating R.
  2. Re-installing/Updating R Studio.
  3. Re-installing/Updating all the packages.
  4. Restarting the R session.
  5. Following the debugging instructions provided here: [https://yihui.org/tinytex/r/].

Unfortunately, the issue persists and the error message continues to appear.

processing file: test2.Rmd

/usr/local/bin/pandoc +RTS -K512m -RTS test2.knit.md --to beamer --from markdown+autolink_bare_uris+tex_math_single_backslash --output test2.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --highlight-style tango --pdf-engine pdflatex --embed-resources --standalone output file: test2.knit.md

! Undefined control sequence. \Oldarrayrulewidth

Error: LaTeX failed to compile test2.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test2.log for more info. Execution halted

The example code used in R Markdown is as above by @davidgohel. As I have 2 Macs, one is M1, and one is Intel, I tried this Rmd file on them and both showed the same error of "! Undefined control sequence. \Oldarrayrulewidth".

Do you have a trick for this?

My session information:

sessionInfo()

R version 4.3.1 (2023-06-16) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Monterey 12.3

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Tokyo tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] gtsummary_1.7.1 kableExtra_1.3.4.9000 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0
[6] dplyr_1.1.2 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1
[11] ggplot2_3.4.2 tidyverse_2.0.0 flextable_0.9.2

loaded via a namespace (and not attached): [1] tidyselect_1.2.0 viridisLite_0.4.2 fastmap_1.1.1 xaringan_0.28 fontquiver_0.2.1
[6] broom.helpers_1.13.0 promises_1.2.0.1 digest_0.6.33 timechange_0.2.0 mime_0.12
[11] lifecycle_1.0.3 ellipsis_0.3.2 gfonts_0.2.0 processx_3.8.2 magrittr_2.0.3
[16] compiler_4.3.1 sass_0.4.6 rlang_1.1.1 tools_4.3.1 gt_0.9.0
[21] utf8_1.2.3 yaml_2.3.7 data.table_1.14.8 knitr_1.43 askpass_1.1
[26] prettyunits_1.1.1 htmlwidgets_1.6.2 pkgbuild_1.4.2 curl_5.0.1 xml2_1.3.5
[31] rsconnect_0.8.29 pkgload_1.3.2.1 httpcode_0.3.0 miniUI_0.1.1.1 withr_2.5.0
[36] grid_4.3.1 fansi_1.0.4 urlchecker_1.0.1 profvis_0.3.8 gdtools_0.3.3
[41] xtable_1.8-4 colorspace_2.1-0 scales_1.2.1 crul_1.4.0 tinytex_0.45
[46] cli_3.6.1 rmarkdown_2.23 crayon_1.5.2 ragg_1.2.5 generics_0.1.3
[51] remotes_2.4.2 rstudioapi_0.15.0 httr_1.4.6 tzdb_0.4.0 sessioninfo_1.2.2
[56] cachem_1.0.8 rvest_1.0.3 vctrs_0.6.3 devtools_2.4.5 webshot_0.5.5
[61] jsonlite_1.8.7 fontBitstreamVera_0.1.1 xaringanthemer_0.4.2 callr_3.7.3 hms_1.1.3
[66] systemfonts_1.0.4 jquerylib_0.1.4 glue_1.6.2 ps_1.7.5 DT_0.28
[71] stringi_1.7.12 gtable_0.3.3 later_1.3.1 munsell_0.5.0 pillar_1.9.0
[76] htmltools_0.5.5 openssl_2.0.6 R6_2.5.1 textshaping_0.3.6 evaluate_0.21
[81] shiny_1.7.4.1 memoise_2.0.1 bslib_0.5.0 fontLibera

dr-phuong avatar Jul 12 '23 06:07 dr-phuong