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 font sizes should respect document default if gt font size option is not set #1852

Open
2 tasks done
capnrefsmmat opened this issue Aug 21, 2024 · 1 comment · May be fixed by #1937
Open
2 tasks done

Table font sizes should respect document default if gt font size option is not set #1852

capnrefsmmat opened this issue Aug 21, 2024 · 1 comment · May be fixed by #1937

Comments

@capnrefsmmat
Copy link

Prework

Proposal

#1594 made gt's LaTeX export respect more of the options/styles set in gt, including font size. Because the default gt font size is 12pt, every gt table rendered to LaTeX includes the following at the beginning:

\fontsize{12.0pt}{14.4pt}\selectfont

But default LaTeX document font sizes are typically 10pt or 11pt, so this makes the tables larger than the text. (Quarto uses scrartcl as the documentclass by default, which defaults to 11pt, for instance.)

As a user this is inconvenient in, say, a large Quarto book with many files, because I'd have to manually set the gt style options every time I load it, and keep those in sync if I adjust the LaTeX.

Prior comment from @kbrevoort in #1594:

The change I meant to make was to handle cases where the user explicitly sets a table-wide font size using tab_options, such as gt1 <- gt(exibble) |> tab_options(table.font.size = px(16)), the as_latex function would change the font size to 12pt immediately before beginning the longtable environment. What I did not anticipate is that if the table was silent about the value of table.font.size, as in gt2 <- gt(exibble), or explicitly set to NULL as in gt3 <- gt(exibble) |> tab_options(table.font.size = NULL) (which is the default parameter value in the help file for tab_options) the value of table.font.size is set to the default value of 12pt. The code in the PR explicitly sets this value of table.font.size.

If that's what you want, I'll update the tests. But as a user, I think my preference would be that unless I explicitly set a value for table.font.size, the LaTeX code should remain silent about the font size used for the table and allow its value (and the other font characteristics) to be determined by the document where it appears.

If you want to go with the latter approach, it will require changing how the table.font.size parameter is stored in the gt_tbl object, which would have implications beyond the LaTeX portion of the code.

I actually would prefer the same logic being applied in other output formats, like HTML. The same thing happens in HTML output, but I only noticed it today because the default font size in Quarto's HTML output is close enough to 12pt that it's not a problem.

@AaronRendahl
Copy link

This happens when rendering to revealjs as well, the tables are too small at 12px and need to be updated. I render to both html and revealjs (and docx) from the same quarto file, so it would be great if it would respect the default font size in each document. For this purpose, it seems to work so far to add tab_options(table.font.size = "100%") to each table, but that seems like it should be unnecessary.

capnrefsmmat added a commit to capnrefsmmat/gt that referenced this issue Jan 1, 2025
In LaTeX and HTML output formats, gt tables previously always set the
font size (see rstudio#1594). If the tables were being inserted into a
document (e.g., in a Quarto document), they did not inherit the font
size of the surrounding document, requiring the user to manually set the
size option for each table.

Instead, the default table.font.size is NA. Leaving it NA causes the
HTML and LaTeX outputs to emit no font size change, so the table is the
same size as the surrounding text in the document (or the browser's
default body font size). If the user manually sets the table.font.size,
it will be respected in both formats.

Fixes rstudio#1852.
@capnrefsmmat capnrefsmmat linked a pull request Jan 1, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants