Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown tables use different style than code (kable) tables #922

Closed
cbrnr opened this issue May 18, 2022 · 9 comments
Closed

Markdown tables use different style than code (kable) tables #922

cbrnr opened this issue May 18, 2022 · 9 comments
Labels
enhancement New feature or request tables Issues with Tables including the gt integration
Milestone

Comments

@cbrnr
Copy link

cbrnr commented May 18, 2022

Consider the following reprex (tested with quarto 0.9.424):

---
title: "Table vs. kable"
engine: knitr
---

A Markdown table is *not* striped:

|  a|  b|  c|
|--:|--:|--:|
|  1|  6| 11|
|  2|  7| 12|
|  3|  8| 13|
|  4|  9| 14|
|  5| 10| 15|

But a table generated with `knitr::kable()` is striped (besides other minor differences):

```{r}
data.frame(a=1:5, b=6:10, c=11:15) |> knitr::kable()
```

Although the output of the code cell is exactly equal to the Markdown table in the example (the first table), the output look different, most notably only the kable is striped:
Screen Shot 2022-05-18 at 16 09 29

I would have expected that the tables use the same style by default. If this is not desired, is there a way I can make them the same?

@jjallaire
Copy link
Collaborator

It's on our short list to make this configurable, but right now tables from data frames are striped (and more compact) and tables within content are not.

@jjallaire jjallaire added this to the Future milestone Jun 7, 2022
@mcanouil
Copy link
Collaborator

mcanouil commented Jul 18, 2023

To note, this can easily be solved:

---
title: "Table vs. kable"
engine: knitr
---

A Markdown table is *not* striped:

|  a|  b|  c|
|--:|--:|--:|
|  1|  6| 11|
|  2|  7| 12|
|  3|  8| 13|
|  4|  9| 14|
|  5| 10| 15|

But a table generated with `knitr::kable()` is striped (besides other minor differences):

```{r}
#| output: asis
data.frame(a=1:5, b=6:10, c=11:15) |> knitr::kable()
```

Also, Quarto table processing can be disable, see https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing.

@mcanouil mcanouil added tables Issues with Tables including the gt integration enhancement New feature or request labels Jul 18, 2023
@cderv
Copy link
Collaborator

cderv commented Jul 18, 2023

I am surprised by this trick of using output: asis on the kable() results to modify the default behavior that we apply on computation tables.

Striped tabled is indeed a default we set for computational table

// default treatment for computational tables
const addTableClasses = (table: Element, computational = false) => {
table.classList.add("table");
if (computational) {
table.classList.add("table-sm");
table.classList.add("table-striped");
table.classList.add("small");
}
};

which is different than our default for non computational table.

but right now tables from data frames are striped (and more compact) and tables within content are not.

@jjallaire what is the reason to make the two style different ? (0a352d6 and 4230513)

most notably only the kable is striped

With new feature in 1.3 (https://quarto.org/docs/prerelease/1.3/tables.html), one can now apply striped to Markdown table easily

(BTW @jjallaire is this the configurable you were mentioning ? or do we plan for more ?)

This example would be the other counterpart to make the Markdown table use the same style as the computational table

---
title: "Table vs. kable"
engine: knitr
---

A Markdown table can be striped:

|  a|  b|  c|
|--:|--:|--:|
|  1|  6| 11|
|  2|  7| 12|
|  3|  8| 13|
|  4|  9| 14|
|  5| 10| 15|

: {.striped .sm .small}

But a table generated with `knitr::kable()` is striped (besides other minor differences):

```{r}
data.frame(a=1:5, b=6:10, c=11:15) |> knitr::kable()
```

Also, Quarto table processing can be disable, see quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing.

@mcanouil Not sure kable processing happens here for knitr output. Are you suggesting to apply that for the Markdown table ?

@mcanouil
Copy link
Collaborator

mcanouil commented Jul 18, 2023

Indeed it does not in this case, Quarto processing would mostly matters when using format = "html" and in combination of kableExtra.
The trick (because it's really is a trick) with output: asis allow to avoid Quarto processing when the markdown table is inside a "cell" div.

@jjallaire
Copy link
Collaborator

The reason they are different is that data looks dramatically better w/ condensed/striped presentation, whereas content often looks worse (they are really two different use cases of table). The solution should be allowing uses to override the default (which I believe we were slated to do in v1.3, not sure if we exposed every required knob).

@cderv
Copy link
Collaborator

cderv commented Jul 18, 2023

that data looks dramatically better w/ condensed/striped presentation, whereas content often looks worse (they are really two different use cases of table).

Oh I see. Did not think of that. Thanks for the precision.

@mcanouil
Copy link
Collaborator

Since it is by design, do we keep this open?

@jjallaire
Copy link
Collaborator

We should close it (and then make sure there is a way for users to override the default behavior that is clearly documented)

@cderv
Copy link
Collaborator

cderv commented Dec 27, 2023

Let's close this and follow work for opting out in #6945

@cderv cderv closed this as completed Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tables Issues with Tables including the gt integration
Projects
None yet
Development

No branches or pull requests

4 participants