quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.95k stars 326 forks source link

`*cap-location` at code cell level is not respected without label #11342

Open mcanouil opened 1 week ago

mcanouil commented 1 week ago

*cap-location at code cell level is not respected without label. (tested on 28bfc55761810dda69b47db801058161ca1fa8bc)

It seems related to a previous fix:

But It seems the fix did not make it all the way in 1.5 regarding the issue.

Adding a label makes the code cell option work.

Note: both fig and tbl are impacted.

InputOutput
````qmd --- title: "Untitled" format: html --- ```{r} #| tbl-cap: MTCARS #| tbl-cap-location: top library(gt) mtcars[1:5, ] |> gt() ``` ```{r} #| tbl-cap: MTCARS #| tbl-cap-location: bottom library(gt) mtcars[1:5, ] |> gt() ``` ```` image
````qmd --- title: "Untitled" format: html --- ```{r} #| label: tbl-one #| tbl-cap: MTCARS #| tbl-cap-location: top library(gt) mtcars[1:5, ] |> gt() ``` ```{r} #| label: tbl-two #| tbl-cap: MTCARS #| tbl-cap-location: bottom library(gt) mtcars[1:5, ] |> gt() ``` ```` image

Originally posted by @mcanouil in https://github.com/quarto-dev/quarto-cli/discussions/11341#discussioncomment-11188545

cderv commented 1 week ago

But It seems the fix did not make it all the way in 1.5 regarding the issue.

I think the fix targeted the markdown syntax for this and it works ok (not consider a style regression on border I am looking into 🤕 )

---
title: Table caption location
tbl-cap-location: bottom
format: html
---

| Col1 | Col2 | Col3 |
|------|------|------|
| A    | B    | C    |
| E    | F    | G    |

: A non-labelled table with a caption

Also it was "fixed" only for HTML.

Here this is related to engine, and tbl-cap-location passed at cell level and not at global level.

The discussion from #9734 still apply here: Most of the tbl- option are happening for FloatRefTarget. So it requires a label.

@cscheid will confirm but I don't think this is a bug here. And it is not a regression as this cell option does not seem to have ever worked from any Quarto version.

mcanouil commented 1 week ago

The "issue" is that the behaviour is not consistent tbl-cap-location:

(My first thought was "there should be a label there".)

mcanouil commented 1 week ago

This could go as a linter issue (for "future") rather than a bug: warn users if they set *cap-location without label in a code cell.

It could also be considered as a documentation issue, i.e., update the reference pages (if possible) to mention that those options require a label to be set: https://quarto.org/docs/reference/cells/cells-knitr.html#page-columns / https://quarto.org/docs/reference/cells/cells-jupyter.html#page-columns

cderv commented 6 days ago

The "issue" is that the behaviour is not consistent tbl-cap-location:

  • works at the global level on non-labelled tables/figures.
  • does not at the code cell level on non-labelled tables/figures.

This makes me think this is a case where should probably not have done #9734 😅 It created this inconsitency with engine, and across format.

So I believe in this case, we wanted this inconsistency for now.

This could go as a linter issue (for "future") rather than a bug: warn users if they set *cap-location without label in a code cell.

This is a good idea if this is doable ! We have probably several combination of options where we could give nice warning / advice.

It could also be considered as a documentation issue, i.e., update the reference pages (if possible) to mention that those options require a label to be set: quarto.org/docs/reference/cells/cells-knitr.html#page-columns / quarto.org/docs/reference/cells/cells-jupyter.html#page-columns

Yes good point now that this is there. More generally, I think this is about the feature for FloatRefTarget only. I think this is not the only one.