quarto-dev / quarto-cli

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

Allow Different Types of Cross Reference-able Outputs from a Single Code Chunk #1229

Closed dragonstyle closed 1 year ago

dragonstyle commented 2 years ago

Sometimes (especially with margin layout), it is useful to place the outputs of a code chunk side by side. To accomplish this, the outputs needs to come from the same chunk (e.g. a table of data and a plot of that data). It would be nice to be able to specify the labels for a chunk as an array, allowing something like:


```{r}
#| label: [tbl-cars, fig-cars]
#| fig-cap: "Cars fig"
#| tbl-cap" "Cars tbl"
#| tbl-column: margin

mtcars2 <- mtcars
mtcars2$am <- factor(
  mtcars$am, labels = c('automatic', 'manual')
)

knitr::kable(
  mtcars[1:6, 1:6]
)

library(ggplot2)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
  geom_point() +  geom_smooth(formula = y ~ x, method = "loess") +
  theme(legend.position = 'bottom')


### Discussed in https://github.com/quarto-dev/quarto-cli/discussions/1201

<div type='discussions-op-text'>

<sup>Originally posted by **mvwestendorp** June 22, 2022</sup>
Is it possible to switch the figure and table in this [example](https://quarto.org/docs/authoring/article-layout.html#multiple-outputs)?  That is, the table in the margin and figure in the body.

Using `#| tbl-column: margin` does not seem to work in this case.</div>
cscheid commented 1 year ago

(This one will be hard to make work for #4944 because it interacts badly with some of the downstream formats we need to support. Leaving it open for future in case we figure out a way to do it.)

mcanouil commented 1 year ago

What if you kinda cheat and make the cell output n cells (I know how to do it in knitr, but here it would require something more agnostic) 🤔 This also comes with some caveats as you would not necessarily know what lines output something ...

cscheid commented 1 year ago

The fundamental problem doesn't go away, which is that if you have a subfigure and a subtable, then you either have an enclosing figure with a subtable or an enclosing table with a subfigure. Neither of those are allowed in LaTeX.

cscheid commented 1 year ago

This is not going to be possible for the foreseeable future, even if the new crossref work that just landed, precisely because of the enclosing float problem, and the inconsistency with counters that we'd get.