-
DescriptionHi. Apologies if the answer to this exists, but I could not find it. I am trying to create a table in a document that compiles to a .docx format. I would like two of the columns to have a little header above them. First, I tried using There are an overwhelming number of packages that will format tables, so then I moved along to {kableExtra}. A table produced using
Is there a trick to getting {kableExtra} to work, or is there a different package that will produce this desired result? Example:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Beta Was this translation helpful? Give feedback.
-
This is currently a limitation from knitr and how kableExtra works, from back then in the R Markdown context. Basically what is happening ? kableExtra is producing an HTML table. However, you target So why am I saying this is a limitation ? Because Quarto has a specific feature of support HTML table, by parsing them to convert to a Table AST element for Pandoc, which makes it possibly to output a Table in the targeted output. knitr or kableExtra currently does not take this into account, and kableExtra does try to include HTML dependencies in Quarto docx output. So seeing a HTML output with HTML deps from a cell inside a non-HTML target format leads to this issue (unless To make it work, something like this could be used
I am surprised by this not working. This is working for me ---
format:
docx: default
keep-md: true
---
```{r}
library(gt)
towny |>
dplyr::slice_max(population_2021, n = 5) |>
dplyr::select(
name, latitude, longitude,
ends_with("2016"), ends_with("2021")
) |>
gt() |>
tab_spanner(
label = "Population",
columns = starts_with("pop")
) |>
tab_spanner(
label = "Density",
columns = starts_with("den")
) |>
tab_spanner(
label = md("*Location*"),
columns = ends_with("itude"),
id = "loc"
)
``` So maybe another issue with gt and Quarto due to other stuff than ![]() Hope it helps understand. |
Beta Was this translation helpful? Give feedback.
-
Thank you. flextable almost worked, but I was hoping to include some latex (sorry, my minimal example was too minimal), which it looks like is not possible? |
Beta Was this translation helpful? Give feedback.
Is this what you have in mind?