gt
gt copied to clipboard
Add opts for caption alignment and/or location for HTML output
Low-priority feature request: Super happy that you've added captions (yay for https://github.com/rstudio/gt/issues/635). Because it's the accessible label for a table for screenreaders, if I only use one title-ish function (e.g. tab_header(),
tab_caption()`) for a table, it's caption. Currently, it listens to position arguments from yaml, but is always above the table and center aligned with gt (as far as I've been able to figure out).
You can get it left aligned with custom CSS, but something like opt_align_caption()
(the caption-equivalent of opt_align_table_header()
) and/or similar options for positioning it relative to the table for HTML output (similar to the arguments for exporting it to word, linked below), would be lovely.
https://github.com/rstudio/gt/blob/7aed84d865c55ddbf1c3d28e2feafabb547687f3/R/export.R#L799-L803
Apologies if this is already possible and I missed it. If so, happy to help with any documentation changes to make it more findable.
Thanks, Rich!
The caption is purposefully a bit non-customizable. This is mostly because (I think) we are leaving it up to Quarto / R Markdown to position it whichever way it can. However, if you're not working with Quarto the lack of customization is a bit disappointing.
I'll probably revisit this a bit (maybe at least add an alignment option) once I get a handle on what Quarto is doing with captions in general.
@batpigandme you can use the tbl-cap-location
YAML option under html:
to set the caption location to bottom
or margin
instead of top
.
https://quarto.org/docs/authoring/tables.html#caption-location
I am still hoping that {gt}
will find a way to target the caption with a tab_style
location, for more friendly caption styling. (see #224 )
Hi,
I agree it would be great if there was a separate caption alignment option. I basically always want my caption on the bottom left, but my figure in the center. Currently the caption matches the alignment of the figure, i.e. fig.align = "center" also places the caption in the center whereas I want the caption to remain on the left... If there would be a way to change this for html outputs that would be fabulous, thank you!