What's your favorite way to export a table to Word in #RMarkdown? I haven't found (or can't remember) a good one for this. In particular, I want to be able to handle LaTeX so that I can include row labels like "\(\textrm{A}\beta_{42}\)". And I'd like the default formatting to be reasonably attractive, if possible. #rstats
@emjonaitis The xtable package might be a good option for this.
@wviechtb I think I've tried this but I don't think it works for Word export - correct me if I'm wrong. (Setting -- drafting a multiauthor paper, so we need the comment & track changes functionality of Word.)
@emjonaitis If you export as HTML, then you can just copy-paste the table from the HTML page into your Word document (or import it).
Huxtable - an R package for writing LaTeX and HTML tables

@granmogul @emjonaitis I summarised possibilities to export #rstats #tables to Word / Excel here: https://www.adrianbruegger.com/post/quick-descriptive-tables/

#tinytable is a new package that also sounds promising

Quickly create descriptive tables in R for MS Word and Excel | Adrian Gadient-Brügger

Presentation of R packages to generate descriptive tables and save them as Word files

Adrian Gadient-Brügger
@granmogul @adriangadientbruegger Thank you for this. I believe tinytable is exactly what I was looking for.
@emjonaitis Hi! I dont know how applicable this is, but with Emacs org-mode, I find It easiest to
1. Make the table with gt
2. Save it as .tex
3. Import the .tex in the document proper
4. Export everything as latex
5. Convert latex to docx with pandoc

@emjonaitis I use {flextable}. I don't think it handles Latex formatting, unfortunately.

https://stackoverflow.com/questions/48028069/latex-formatting-in-word-using-rmarkdown-and-flextable

LaTeX formatting in Word using Rmarkdown and flextable

I have a table that contains column headers with LaTeX formatting (e.g., Lower CI$_{95\\%}$). When I render the table in HTML or PDF format using knitr::kable, they display the correct formatting, ...

Stack Overflow
@rmflight Yeah, that's what I'm seeing also, so thanks for confirming. It's unintuitive to me how difficult it is to embed Latex into a table for Word output when it's so easy to do it in the body of the text.

@emjonaitis Not sure the font system in Word looks great, but this seemed to work for me:
```
library(flextable)

pars <- as_paragraph(as_equation("\\lparen\\textrm{A}\\beta_{42}\\rparen"))

ft <- flextable(head(mtcars)) |>
add_header_row(values = pars,
colwidths = 11, top = FALSE
)

ft
```

Interesting. Is the "\\lparen" there serving as a LaTeX delimiter? Could I substitute a literal left parenthesis or no?
@emjonaitis I tried `\\(` first, and got an error. For some reason, the packages I found seem to use katex, so I looked up the corresponding syntax on https://katex.org/docs/supported
Supported Functions · KaTeX

This is a list of TeX functions supported by KaTeX. It is sorted into logical groups.

@emjonaitis

Let us know, which solution you preferes