This is a follow-up to this question. Basically, my idea is that I create a dummy table which does not produce any visible output, but produces a caption and a reference to use. I got a semi-working result with this:
---
title: "Example"
format: html
---
This is already something (@tbl-test), but the output does not look nice.
: Another table test {#tbl-test}
------ ------
```{r}
#| label: tbl-iris
#| tbl-cap: Example DT table
DT::datatable(head(iris))
```
The output is not perfect, there is a stub of a table that one could mistake for some kind of an underline, but I get my cross references, captions, list of tables etc. Is there a simple way of making this actual table go away completely? Maybe some css magic?
CodePudding user response:
You can set the display: none
to remove the table body.
---
title: "Example"
format: html
---
```{css, echo=FALSE}
div[id^='tbl-test'] thead,
div[id^='tbl-test'] tbody {
display: none;
}
div[id^='tbl-test'] table {
margin-bottom: 0;
}
```
This is something (@tbl-test), and (@tbl-test1) and @tbl-test_anotherone
: Another table test {#tbl-test}
------ ------
```{r}
#| label: tbl-iris
#| tbl-cap: Example DT table
DT::datatable(head(iris))
```
: Another table test-01 {#tbl-test1}
------ ------
: Another table test-anotherone {#tbl-test_anotherone}
------ ------