Formatos de súperindices con la librería GT

Dear community.

I need your help, I need to know if there is any way to assign the order to the different superscripts,
I will tell you my situation I have a superscript in the spanner which is the number (1) and in one of the columns before the spanner I have the superscript (2), so GT assigns it to me by default.

What I want is to know how to manipulate my tab_footnote so that it looks like this:
Superscript (1) in column 1 and superscript 2 in the spanner.

I will appreciate your contributions since I don't know what to do anymore, please.

Greetings.


Estimada comunidad.

Necesito de su ayuda, necesito saber si hay alguna forma de asignarle el orden a los superíndices diferentes,
les cuento mi situación tengo un superíndice en el spanner el cual es el número (1) y en una de las columnas antes del spanner tengo el superíndice (2), así me lo asigna GT por default.

Lo que quiero es saber manipular mis tab_footnote para que quede se la siguiente manera:
El superíndice (1) en la columna 1 y el superíndice 2 en el spanner.

Les agradeceré sus aportes dado que ya no se que hacer, por favor.

Saludos.

Hi @Paula.A
Welcome to the Posit/RStudio Community Forum.

If I understand your request correctly, you want to control the order in which your footnotes are labelled as superscripts. Try this:

library(gt)
library(tidyverse)
# Get small dataframe for illustration
mtcars %>% 
  rownames_to_column("Car_model") %>%
  select(1:4) %>% 
  slice_head(n=6) -> df

gt_tbl <- gt(df)

gt_tbl %>% 
  tab_spanner(label = "Specifications",
              columns = 2:4,
              id = "specs") %>% 
  tab_footnote(footnote = "Engine displacement",
               locations = cells_column_labels(columns = disp)) %>% 
  tab_footnote(footnote = "Various engine and performance data",
               locations = cells_column_spanners(spanners = "specs")) %>% 
  tab_options(footnotes.marks=c('2','1'))

I can't post the output because the gt tables don't render accurately.

1 Like

Hello, thank you very much, it really helped me with my problem.

Nice afternoon. :hugs:

1 Like

Hello @DavoWW, one last question. Do you know if it could be formatted so that the superscripts do not appear italic, please?

You can achieve this with the following formatting command which you add to the end of the existing code:

...... %>%
 opt_footnote_spec(spec_ref = "^x", spec_ftr = "^x")

All these options, and many more, are detailed here:
https://gt.rstudio.com/articles/intro-creating-gt-tables.html

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.