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

Table prefix crossref removes left alignment of gtsummary footnotes #11935

Open
dchiu911 opened this issue Jan 23, 2025 · 2 comments
Open

Table prefix crossref removes left alignment of gtsummary footnotes #11935

dchiu911 opened this issue Jan 23, 2025 · 2 comments
Assignees
Labels
bug Something isn't working tables Issues with Tables including the gt integration upstream Bug is in upstream library

Comments

@dchiu911
Copy link

dchiu911 commented Jan 23, 2025

Bug description

The footnotes generated at the bottom of a gtsummary table by e.g. tbl_summary() are left aligned by default. When using the tbl- prefix for cross-referencing the table caption, the footnotes become centered

Steps to reproduce

---
title: "Untitled"
execute: 
  echo: false
---

```{r}
#| label: load

library(gt)
library(gtsummary)
```

```{r}
#| label: example-1 
#| tbl-cap: "Caption without crossref"

trial |>
  select(age, grade, response) |>
  tbl_summary()
```

```{r}
#| label: tbl-example-2
#| tbl-cap: "Caption with Crossref but center aligned footnote"

trial |>
  select(age, grade, response) |>
  tbl_summary()
```

```{r}
#| label: tbl-example-3
#| tbl-cap: "Caption with correct Crossref"

trial |>
  select(age, grade, response) |>
  tbl_summary() |> 
  as_gt() |> 
  tab_style(style = cell_text(align = "left"),
            locations = cells_footnotes())
```

Expected behavior

Footnotes are left aligned when cross-referencing is used but I have to use additional formatting from package gt. This is the output from chunk tbl-example-3.
Image

Actual behavior

Footnotes are left aligned when no cross-referencing is used (output from example-1), but when cross-referencing is used footnotes are centre aligned (output from tbl-example-2).

Image Image

Your environment

  • IDE: RStudio/2024.12.0+467
  • macOS Sequoia 15.1

Quarto check output

Quarto 1.7.13
[✓] Checking environment information...
      Quarto cache location: /Users/derekchiu/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.7.13
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/derekchiu/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking Chrome Headless....................OK
      Using: Chrome found on system
      Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
      Source: MacOS known location

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.13.1
      Path: /opt/homebrew/opt/[email protected]/bin/python3.13
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.4.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Users/derekchiu/Library/R/arm64/4.4/library
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: 1.49
      rmarkdown: 2.29

[✓] Checking Knitr engine render......OK
@dchiu911 dchiu911 added the bug Something isn't working label Jan 23, 2025
@cderv
Copy link
Collaborator

cderv commented Jan 23, 2025

Thanks for the report.

This is centered because this CSS is inserted and applies on the table

.quarto-figure-center>figure>p, .quarto-figure-center>figure>div {
    text-align: center;
}

Which is the default behavior for content in crossref element to be centered

It is not specific to table, but it will apply on it because no style specific to the table override this.
Other rows have specific styling applied to them by gt (e.g using gt_left class )

<td class="gt_row gt_left" headers="label">Grade</td> 

So the alignment in the first table is left by default for the footnote, but this is inherit default from body. Which that the table content alignment does not seem to be protected against some global default

So if gtsummary wants to apply so default alignment, it should probably apply some table inline styling. I don't know if this is gt or gtsummary

When doing

tab_style(style = cell_text(align = "left"),
            locations = cells_footnotes())

it works because some inline style are now set on the footnote

<td colspan="2" class="gt_footnote" style="text-align: left;"><span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span> Median (Q1, Q3); n (%)</td>

and so the .quarto-figure-center rule does not apply to it.

To sump, I don't think this is an issue to handle in Quarto directly, but something in gtsummary or gt to adapt to prevent external CSS to modify a default they expect maybe.

Hope it helps

@mcanouil mcanouil added support a request for support and removed bug Something isn't working labels Jan 23, 2025
@cderv
Copy link
Collaborator

cderv commented Jan 23, 2025

I can confirm this is gt. Here is a reprex with default gt

---
title: "Untitled"
execute: 
  echo: false
keep-md: true
---

```{r}
library(gt)
```

```{r}
#| label: gt_tab
gt::films[1:5, 1:2] |> 
  gt() |> 
  tab_footnote(footnote = "A footnote")
```


::: {#tbl-gt}
```{r}
#| label: gt_tab
```

Same gt table as above but cross referencable
:::

See @tbl-gt

Image

@rich-iannone I think this is something we could improve in gt. It seems tab_footnote() default is not protected against external CSS applying on wrapper element.

@cderv cderv added bug Something isn't working upstream Bug is in upstream library tables Issues with Tables including the gt integration and removed support a request for support labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tables Issues with Tables including the gt integration upstream Bug is in upstream library
Projects
None yet
Development

No branches or pull requests

4 participants