cols_width setting seems to be ignored and dont understand why

Hi I am loving using the great_tables library after hearing about it on talkpython.fm. I am trying to format some wide text using cols_width, but the setting seems to be ignored.
The "Alignment" column I need to format text represents a Protein Sequence aligment and these are best showed with a fixed width font and with column width larger than the length of the alignment.

In great_tables running inside Jupyter I get


ProtA_MSA 3 efsdeywmreal.lakkaaderevpvgavvv.ndevigegwnra.glhdptaHAeilalr.aalklqnyRLldatl.vtlePcvmcagaiih.rigrvvfGardaktg.agslmdllqepglnh.veitegvladecaa.LseFfrk 140 ef +eywmr+al la++a+de+evpvgav+v n++vigegwnra glhdptaHAei+alr ++l+lqnyRL+d+tl vt+ePcvmc ga++h rig +vfG+r++k g agslm++l++pg+nh v+ gvla ec+ L++F+r+ newseq2_2024_1234_2_1_222_PRT_proc.txt 5 EFTHEYWMRHALtLARRARDEGEVPVGAVLVlNNQVIGEGWNRAiGLHDPTAHAEIMALRqGGLVLQNYRLIDTTLyVTFEPCVMCSGAMVHsRIGTLVFGVRNSKRGaAGSLMNVLNYPGMNHqVKTIGGVLAPECSGlLCDFYRM 151 799*********99**************765167**************************99**********************************************9****************99999********989****96 PP

Here the text does not visually indicate alignment , for eg the text "efsdey" should be on top of "EFTHEY". How do I get the alignment to look right in the tables. I am having a hard time understanding the syntax for cols_width and specifying a fixed-width font.

from great_tables import style,loc
merge_table_retry = (
    GT(df_weird_merge)
    .cols_width(
    cases = {
    "Alignment" : "2000px",
    }
    )
    .tab_header(
        title="LPGID Editor Performance",
        subtitle="Ranked by mean activity"
    )
    .fmt_number(
        columns=['min_activity', 'max_activity', 'mean_activity', 'std_activity','Percent Identity'],
        decimals=2
    )
    .fmt_integer(
        columns=['count']
    )
    .tab_source_note(
        source_note="Data based on activity measurements across different gRNAs"
    )
    .tab_spanner(
        label="Activity Statistics",
        columns=['min_activity', 'max_activity', 'mean_activity', 'std_activity']
    )
    .cols_label(
        editor="LPGID Editor",
        count="Data Points",
        min_activity="Min",
        max_activity="Max",
        mean_activity="Mean",
        std_activity="Std Dev",
        Alignment="Alignment",
    ) 
    .fmt_nanoplot(
        columns="mean_activity",
        plot_type="bar"
    )
     .tab_style(
        style=style.fill(color="lightblue"),
        locations=loc.body(columns=['mean_activity'])
    )
    .tab_style(
        style=style.text(weight="bold"),
        locations=loc.body(columns=['editor'])
    )
     .tab_style(
        style=style.text(font="monospace"),
        locations=loc.body(columns=['Alignment'])
    )
    .tab_style(
        style=style.text(whitespace="monaco"),
        locations=loc.body(columns=['Alignment'])
    )
)

Please can you help with an example. I tried to read the cols_width Reference page , but was not understanding how to get this to look right

Thanks

1 Like