Last active
January 18, 2024 04:51
-
-
Save andrewheiss/2f826560732a331a0c78704819042c92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| title: "Table cross referencing stuff" | |
| format: | |
| html: default | |
| pdf: default | |
| docx: | |
| prefer-html: true # Because kableExtra complains | |
| --- | |
| ```{r setup, warning=FALSE, message=FALSE} | |
| library(tidyverse) | |
| tbl_example <- tibble( | |
| `Column 1` = c("A", "D", "G"), | |
| `Column 2` = c("B", "E", "H"), | |
| `Column 3` = c("C", "F", "I") | |
| ) | |
| ``` | |
| ## Raw Markdown | |
| See @tbl-md. | |
| | Column 1 | Column 2 | Column 3 | | |
| |----------|----------|----------| | |
| | A | B | C | | |
| | D | E | F | | |
| | G | H | I | | |
| : Some letters with Markdown {#tbl-md} | |
| :::: {.content-visible when-format="pdf"} | |
| \newpage | |
| ## Raw LaTeX | |
| See @tbl-tex. | |
| ::: {#tbl-tex} | |
| ```{=latex} | |
| \begin{tabular}{@{}lll@{}} | |
| \toprule | |
| Column 1 & Column 2 & Column 3 \\ \midrule | |
| A & B & C \\ | |
| D & E & F \\ | |
| G & H & I \\ \bottomrule | |
| \end{tabular} | |
| ``` | |
| Some letters with LaTeX | |
| ::: | |
| :::: | |
| ::: {.content-visible unless-format="docx"} | |
| \newpage | |
| ## {kableExtra} | |
| See @tbl-kableExtra. | |
| ```{r} | |
| #| label: tbl-kableExtra | |
| #| tbl-cap: "Some letters with kableExtra" | |
| #| message: false | |
| # Weird bug with Quarto and kable_styling and captions and full_width :shrug: | |
| # https://github.com/quarto-dev/quarto-cli/issues/6417 | |
| library(kableExtra) | |
| tbl_example |> | |
| kbl(booktabs = TRUE) |> | |
| kable_styling(full_width = TRUE) | |
| ``` | |
| ::: | |
| \newpage | |
| ## {gt} | |
| See @tbl-gt. | |
| ```{r} | |
| #| label: tbl-gt | |
| #| tbl-cap: "Some letters with gt" | |
| # In Quarto, gt captions can be defined with gt::set_caption(), but they don't | |
| # seem to work with cross references in PDF/LaTeX or Word, so they should be | |
| # defined in the chunk options instead | |
| library(gt) | |
| tbl_example |> | |
| gt() | |
| ``` | |
| \newpage | |
| ## {flextable} | |
| See @tbl-flextable. | |
| ```{r} | |
| #| label: tbl-flextable | |
| #| tbl-cap: "Some letters with flextable" | |
| #| message: FALSE | |
| # In Quarto, flextable captions have to be defined in the chunk options | |
| # https://davidgohel.github.io/flextable/reference/set_caption.html#using-quarto- | |
| library(flextable) | |
| tbl_example |> | |
| flextable() | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment