gt icon indicating copy to clipboard operation
gt copied to clipboard

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

Open capnrefsmmat opened this issue 6 months ago • 1 comments

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.

capnrefsmmat avatar Aug 21 '24 23:08 capnrefsmmat