posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.44k stars 50 forks source link

Add the `opt_table_font()` method #272

Closed rich-iannone closed 1 week ago

rich-iannone commented 2 months ago

This adds the opt_table_font() method, which can be used for the easy addition of fonts (or a font stack) to the table. Here's an example where a font stack was used:

from great_tables import GT, exibble

gt_ex = (
    GT(exibble.head(5), rowname_col="row", groupname_col="group")
    .tab_header("THE HEADING", "(a subtitle)")
    .tab_stubhead("THE STUBHEAD")
    .tab_source_note("THE SOURCE NOTE")
    .opt_table_font(stack="industrial")
)

gt_ex
opt_table_font_font_stack

Here's another example where a single font name is prepended to the list of default fonts:

from great_tables import GT, exibble

gt_ex = (
    GT(exibble.head(5), rowname_col="row", groupname_col="group")
    .tab_header("THE HEADING", "(a subtitle)")
    .tab_stubhead("THE STUBHEAD")
    .tab_source_note("THE SOURCE NOTE")
    .opt_table_font(font="Comic Sans MS")
)

gt_ex
opt_table_font_prepend_font

Fixes: https://github.com/posit-dev/great-tables/issues/175

rich-iannone commented 2 months ago

Sounds good. PR #260 is ready for a re-review.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.

Project coverage is 86.45%. Comparing base (4f1af8d) to head (41b2a0f).

:exclamation: Current head 41b2a0f differs from pull request most recent head 11ddbb6

Please upload reports for the commit 11ddbb6 to get more accurate results.

Files Patch % Lines
great_tables/_options.py 85.29% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #272 +/- ## ========================================== + Coverage 86.44% 86.45% +0.01% ========================================== Files 42 42 Lines 4654 4689 +35 ========================================== + Hits 4023 4054 +31 - Misses 631 635 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

rich-iannone commented 1 week ago

I've incorporated your suggestions in two commits. If CI passes I'll merge this PR. Thanks!