Here I compare a three different ways to make tables. Unfortunately the table numbers and cross-references are still not working as of Quarto version 1.2.335 (Feb 2023), but the developers are aware and a major revamp of cross-referencing is in the works to fix these problems.
6.1 Kable
Here is the {kable} table Table 6.1. Word output is often not good looking. This is a known issue with kable.
Code
library(knitr)library(kableExtra)# note hold_position not working in Quarto v1.0.38.kbl(dt, booktabs =TRUE) %>%kable_styling(latex_options =c("scale_down")) %>% kableExtra::footnote(symbol =c(f1, f2))
Table 6.1: kable: This should have a number that follows the other tables.
mpg
cyl
disp
hp
drat
wt
qsec
vs
am
gear
carb
Mazda RX4
21.0
6
160.0
110
3.90
2.620
16.46
0
1
4
4
Mazda RX4 Wag
21.0
6
160.0
110
3.90
2.875
17.02
0
1
4
4
Datsun 710
22.8
4
108.0
93
3.85
2.320
18.61
1
1
4
1
Hornet 4 Drive
21.4
6
258.0
110
3.08
3.215
19.44
1
0
3
1
Hornet Sportabout
18.7
8
360.0
175
3.15
3.440
17.02
0
0
3
2
Valiant
18.1
6
225.0
105
2.76
3.460
20.22
1
0
3
1
Duster 360
14.3
8
360.0
245
3.21
3.570
15.84
0
0
3
4
Merc 240D
24.4
4
146.7
62
3.69
3.190
20.00
1
0
4
2
Merc 230
22.8
4
140.8
95
3.92
3.150
22.90
1
0
4
2
Merc 280
19.2
6
167.6
123
3.92
3.440
18.30
1
0
4
4
* Here is a footnote about this table
† Here is a second footnote.
6.1.1kable quirks
Make sure to put always_allow_html: true in the yaml at the top of your Rmd or qmd file if outputting to Word. I can’t figure out how to put it in the `
Word output is often not good looking. This is a known issue with kable
Do not pass in caption to kbl() if you want to use Quarto’s cross-reference engine.
kbl(..., format="pandoc") can help for Word if your templates stop working but destroys the PDF output.
6.2flextable
Here is the {flextable} table Table 6.2 (note this is broken in Word output). {flextable} gives you a lot more control over your tables with a grammar format (like ggplot2). It also gives nice output to Word, PDF and HTML. Sadly in Quarto v1.2.335 cross-reference and table numbers for Word is broken, but the developers know about this. The {officer} package, which I think Quarto is leaning on for Word generation, use {flextable} so I am hoping that {flextable} gets moved into the RStudio suite.
flextable: This should have a number that follows the other
tables.
mpga
cylb
disp
hp
drat
wt
qsec
vs
am
gear
carb
21.0
6
160.0
110
3.90
2.620
16.46
0
1
4
4
21.0
6
160.0
110
3.90
2.875
17.02
0
1
4
4
22.8
4
108.0
93
3.85
2.320
18.61
1
1
4
1
21.4
6
258.0
110
3.08
3.215
19.44
1
0
3
1
18.7
8
360.0
175
3.15
3.440
17.02
0
0
3
2
18.1
6
225.0
105
2.76
3.460
20.22
1
0
3
1
14.3
8
360.0
245
3.21
3.570
15.84
0
0
3
4
24.4
4
146.7
62
3.69
3.190
20.00
1
0
4
2
22.8
4
140.8
95
3.92
3.150
22.90
1
0
4
2
19.2
6
167.6
123
3.92
3.440
18.30
1
0
4
4
aHere is a footnote about this table
bHere is a second footnote.
6.2.1flextable quirks
Table numbers and cross-refs broken in Word. Known issue.
6.3gt
Here is the {gt} table Table 6.3 (note this is broken in Word output). {gt} has many of the same features as {flextable} and is in the RStudio suite so maybe it’ll get more Quarto support in the long run. But like {kable}, the Word output is not good. In addition, currently table captions are broken in Quarto Word output.
---always_allow_html: true---```{r warning=FALSE, echo=FALSE, message=FALSE}knitr::opts_chunk$set(echo =FALSE, warning=FALSE, message=FALSE)source(here::here("tables", "_common.R"))```# Kable vs Flex vs qt {#sec-kableflexgt}Here I compare a three different ways to make tables. Unfortunately the table numbers and cross-references are still not working as of Quarto version 1.2.335 (Feb 2023), but the developers are aware and a major revamp of cross-referencing is in the works to fix these problems.```{r}tbl_cap <-"This should have a number that follows the other tables."dt <- (mtcars[1:10,])f1 <-"Here is a footnote about this table"f2 <-"Here is a second footnote."```## KableHere is the {kable} table @tbl-kable. Word output is often not good looking. This is a known issue with `kable`.```{r}#| label: tbl-kable#| tbl-cap: !expr paste("kable:", tbl_cap)#| echo: truelibrary(knitr)library(kableExtra)# note hold_position not working in Quarto v1.0.38.kbl(dt, booktabs =TRUE) %>%kable_styling(latex_options =c("scale_down")) %>% kableExtra::footnote(symbol =c(f1, f2))```### `kable` quirks- Make sure to put `always_allow_html: true` in the yaml at the top of your Rmd or qmd file if outputting to Word. I can't figure out how to put it in the \`- Word output is often not good looking. This is a known issue with `kable`- Do not pass in caption to `kbl()` if you want to use Quarto's cross-reference engine.- `kbl(..., format="pandoc")` can help for Word if your templates stop working but destroys the PDF output.## `flextable`Here is the {flextable} table @tbl-flex (note this is broken in Word output). {flextable} gives you a lot more control over your tables with a grammar format (like ggplot2). It also gives nice output to Word, PDF and HTML. Sadly in Quarto v1.2.335 cross-reference and table numbers for Word is broken, but the developers know about this. The {officer} package, which I think Quarto is leaning on for Word generation, use {flextable} so I am hoping that {flextable} gets moved into the RStudio suite.```{r}#| label: tbl-flex#| tbl-cap: !expr paste("flextable:", tbl_cap)#| echo: truelibrary(flextable)dt %>%flextable() %>%autofit() %>% flextable::footnote(i =1, j =1:2,value =as_paragraph(c(f1, f2)),ref_symbols =c("a", "b"),part ="header") %>%font(fontname="Times New Roman", part="all") %>%fontsize(size=12)```### `flextable` quirks- Table numbers and cross-refs broken in Word. Known issue.## `gt`Here is the {gt} table @tbl-gt (note this is broken in Word output). {gt} has many of the same features as {flextable} and is in the RStudio suite so maybe it'll get more Quarto support in the long run. But like {kable}, the Word output is not good. In addition, currently table captions are broken in Quarto Word output.```{r}#| label: tbl-gt#| tbl-cap: !expr paste("gt:", tbl_cap)#| echo: truedt %>% gt::gt() %>% gt::tab_source_note(source_note = f1) %>% gt::tab_source_note(source_note = f2) %>% gt::tab_options(table.font.size = gt::px(18), table.font.names ="Times New Roman",data_row.padding = gt::px(1))```### `gt` quirks- I couldn't get {gt} to respect my font request for HTML unlike for {flextable}- The footnotes look bad in Word. But I don't know {gt} so probably my error.- Table captions and numbers broken in Word.```{=openxml}<w:p><w:r><w:br w:type="page"/></w:r></w:p>```