tables numbering in quarto

I am not sure if it is a bag of quarto but when i choose to position two tables side by side in a pdf document using gt, flextable or kable tables the numbering starts from three.
When I have tbl-cap-location: top the tables' numbering is correct.
Is it something easy can be done to fix this?

---
title: "two tables  in Two Columns"
format: 
  pdf:
    fig-pos: H
    tbl-cap-location: bottom
 pdf-engine: lualatex
documentclass: scrartcl
number-sections: true
editor: source
execute: 
  echo: false
  warning: false
---

```{r}
df1 <- data.frame(
  ID = c(1, 2, 3),
  Name = c("Alice", "Bob", "Charlie"),
  Age = c(25, 30, 35)
)
df2 <- data.frame(
  ID = c(4, 5, 6),
  Name = c("David", "Eve", "Frank"),
  Age = c(40, 45, 50)
)
```

```{r}
#| label: tbl-dfs
#| tbl-cap: dfs test
#| layout: "[[1,1]]"

library(gt)
gt(df1)
gt(df2)
```
1 Like

Hi, welcome to the forum.

I don't seem to be able to reproduce the problem. I am getting this.
tab1

Is it what you wele expecting?

Not quite.
This is what I want to get, but the numbering is wrong. Also the table you generated it different from what I generate using gt or flextable packages

Screenshot 2025-01-03 at 14-38-24 Four Images in Two Columns - test.pdf

I thought my version was weird but as far as I can see I just copied and pasted your code. Copying .qmd code from the forum to R can be a bid dicy so I must have done something wrong.

I was expecting what you get but I've never done side-by-side plots in Rmarkdown. In LaTeX one would use sub-figures IIRC.

Well, back to the drawing board to see where I went wrong.

Just tried again and got this. Well, the caption is correct :frowning:
nik_tab2

Once again to the {figurative} drawing board.

Enclose your qmd code in the original post with 4 backticks so we can see the 3 back ticks.

Quarto does not make it easy to find out anything about doing this! But I think I may have something. This post Side-by-side tables has a nice working solution. I have not found any way to move the sub-captions. Without them we are back to "Table 3".

If you want something without sub-captions, I think it can be done in LaTeX but I suspect not easily in Quarto though I could be missing the obvious.

My YAML is quite a bit different from yours but I think it still does roughly what you want.

---
title: "Quarto Example Document"
author: "john the toucanite"
date: today
pdf-engine: lualatex
format: pdf
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
---

```{r pkgs}
#| label:   Load_packages
#| include: false

library(kableExtra)

```


I think $\sqrt{a^{2}+b^{2}}$ is correct. Proceeding on from there, we now attempt the impossible in @tbl-hydra.

```{r}
#| label: load_data
#| include: false

df1 <- data.frame(ID = c(1, 2, 3),
  Name = c("Alice", "Bob", "Charlie"),
  Age = c(25, 30, 35))

df2 <- data.frame(ID = c(4, 5, 6),
  Name = c("David", "Eve", "Frank"),
  Age = c(40, 45, 50))
```

```{r plots}
#| label: make_plots
#| echo: false

alpha <- kable(df1)
beta <- kable(df2)
```


```{r hydra}
#| label: tbl-hydra
#| echo: false 
#| tbl-cap: Hydra
#| tbl-subcap: ["Alpha", "Beta"]
#| tbl-cap-location: bottom
#| layout-ncol: 2

# table on the left
alpha

# table on the right
beta
```




P.S. I strongly disapprove of a table caption at the bottom. It is unnatural. :grinning:

Ah, thanks. I thought there should be a way but never considered anything that easy.

I was missing the obvious. If I use {tinytable} to generate the codes rather than {kableExtra} do not get the sub-captions. I have not tried {gt}.

Unfortunately not. This is what I get

Somewhere along the way today I got something similar but the

layout-ncol: 2

seemed to cure it. You are in a Quarto document so there should not anything in your environment. I have been having a bit of a problem getting the @ label command to work at times but the table should have worked.

Try my {tinytable} version and see what happens

---
title: "Side-bySide {tinytable} Example"
author: "John the Toucanite"
date: today
pdf-engine: lualatex
format: pdf
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
---

```{r pkgs}
#| label:   Load_packages
#| include: false

library(tinytable)
```


I think $\sqrt{a^{2}+b^{2}}$ is correct. Proceeding on from there, we now attempt the impossible in @tbl-hydra.

```{r}
#| label: load_data
#| include: false

df1 <- data.frame(ID = c(1, 2, 3),
  Name = c("Alice", "Bob", "Charlie"),
  Age = c(25, 30, 35))

df2 <- data.frame(ID = c(4, 5, 6),
  Name = c("David", "Eve", "Frank"),
  Age = c(40, 45, 50))
```

```{r tables}
#| label: make_tables
#| echo: false

alpha <- tt(df1)
beta <- tt(df2)
```


```{r hydra}
#| label: tbl-hydra
#| echo: false 
#| tbl-cap: Hydra
#| tbl-cap-location: bottom
#| layout-ncol: 2

# table on the left
alpha

# table on the right
beta
```

This is what I am getting.

I was not aware of tinytable package. I am using flextable mainly. It seems though that tinytable package provides the right table numbering. I may need to migrate to this package. I wonder though if this offers the flexibility of flextable.
Thanks

I have just started using {tinytable} a couple of months ago but my impression in that it is rather versatile although I am not sure it offers all the bells and whistles of {flextable} or {gt}.

My impression has been that it is rather good for scientific tables. For one thing it makes adding table footnotes a breeze. The tutorial/manual is rather good too.

One peculiarity that I found is that {tinytable} seems intended to work with Quarto or RMarkdown. If you want a stand-alone table it will insist on putting the caption under the table!

To get it to put the caption an top you need to use this

tt(iris, caption = "Wild flowers") |>
  style_tt(bootstrap_css_rule = "table{caption-side: top;}")

My thanks to @ keithn for this solution.