Skip to content

Repeated figure caption when figure and table captions are mixed #1269

Open

Description

@cscheid

Repro:

---
title: "sidebyside"
format: pdf
editor: visual
keep-tex: true
---

```{r}
#| layout-ncol: 2
#| layout-valign: bottom
#| fig-cap: "A plot"
#| tbl-cap: "A table"

library(knitr)

# plot on the left
plot(cars)

# table on the right
kable(head(cars))
```

Note the duplicated caption on the figure:

image

Activity

  1. added this to the Future milestone on Jul 5, 2022
  2. mcanouil commented on Apr 28, 2024

    @mcanouil
    Collaborator

    FYI, still happening with 1.4 cross-reference system.

  3. added
    bug
    tables
    on Apr 28, 2024
  4. cderv commented on May 27, 2024

    @cderv
    Member

    looking at the intermediate .md for this example lead me to believe this is something with knitr happening.

    Smaller examples where we can see fig-cap is somehow not ignored and put below the table produced by knitr

    ---
    title: "fig-cap table"
    format: html
    keep-md: true
    ---
    
    ```{r}
    #| fig-cap: "A plot"
    library(knitr)
    kable(head(cars))
    ```
    

    Intermediate .md is

    ---
    title: "fig-cap table"
    format: html
    keep-md: true
    ---
    
    
    ::: {.cell}
    
    ```{.r .cell-code}
    library(knitr)
    kable(head(cars))
    ```
    
    ::: {.cell-output-display}
    
    
    | speed| dist|
    |-----:|----:|
    |     4|    2|
    |     4|   10|
    |     7|    4|
    |     7|   22|
    |     8|   16|
    |     9|   10|
    
    
    
    A plot
    :::
    :::

    So this is happening before any Quarto cross ref happening

  5. cderv commented on May 27, 2024

    @cderv
    Member

    I can confirm this is us adding the duplicate

    • We append caption when wrapping asis output content
      # generate output div
      caption <- figure_cap(options)[[1]]
      if (nzchar(caption)) {
      x <- paste0(x, "\n\n", caption)
      }

      and a kable() is outputing asis_output() content
    • figure_cap is today not reacting to content
      figure_cap <- function(options) {
      output_label <- output_label(options)
      if (is.null(output_label) || is_figure_label(output_label)) {
      fig.cap <- options[["fig.cap"]]
      fig.subcap <- options[["fig.subcap"]]
      if (length(fig.subcap) != 0)
      fig.subcap
      else if (length(fig.cap) != 0)
      fig.cap
      else
      ""
      } else {
      ""
      }
      }

    This comes from first support for tbl caption 81d58ed

    and I believe fixing this is part of the broader topic of teaching our computation engine out floats and correct markdown intermediate they should output

    and related to

  6. added
    engines-knitr
    on May 27, 2024
  7. self-assigned this
    on May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcomputationscrossrefengines-knitrfigurestables

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions