[ANN] PrettyTables.jl v0.6.0


I have just requested a new version of PrettyTables.jl to be tagged. The changes are:

  • The format of the horizontal line in the table, which are drawn using the option hlines, can now be selected using the keyword hlines_format.
  • The alignment of a single cell can now be changed regardless of the column alignment. This can be achieve by the keyword cell_alignment.
  • The line between the header and the data can now be hide using the variable header_line of the structure PrettyTableFormat.
  • New predefined highlighters: hl_cell, hl_col, hl_row, which can be used to apply highlights to single cells or to entire columns or rows, respectively.
  • The formatter ft_printf is now only applied to cells that are of type Number. (Issue [#19][gh-issue-19])
  • The formatter ft_printf can now receive one integer if the user wants to format only a single column.
  • End of support of Julia 1.1. The supported versions are 1.0 and 1.2.

I needed the additional options and configuration possibilities to be able to print text reports for a project I am working on related to SatelliteToolbox.jl. Thus, we now can do the following:

julia> data = ["Torques" "" "" "";
               "Atmospheric drag" "."^10 10 "10⁻⁵ Nm";
               "Gravity gradient" "."^10 3 "10⁻⁵ Nm";
               "Solar radiation pressure" "."^10 0.1 "10⁻⁵ Nm";
               "Total" "."^10 13.1 "10⁻⁵ Nm";
               "" "" "" ""
               "Angular momentum" "" "" "";
               "Atmospheric drag" "."^10 6.5 "Nms";
               "Gravity gradient" "."^10 3.0 "Nms";
               "Solar radiation pressure" "."^10 1.0 "Nms";
               "Total" "."^10 10.5 "Nms"]

julia> pretty_table(data, borderless;
                    noheader = true,
                    cell_alignment = Dict( (1,1) => :l, (7,1) => :l ),
                    formatter = ft_printf("%10.1f", 2),
                    highlighters = (hl_cell( [(1,1);(7,1)], crayon"bold"),
                                    hl_col(2, crayon"dark_gray"),
                                    hl_row([5,11], crayon"bold yellow")),
                    hlines = [1,7],
                    hlines_format = Tuple('─' for _ = 1:4) )

to create this text report:


For anyone confused by why this example doesn’t work yet (as I was), it’s not yet merged into the General Registry. Presumably that will change in a few hours (see https://github.com/JuliaRegistries/General/pull/3748).


this does look nice, can it be made to work with JuliaDB and DataFrames things?


Sorry! I completely forgot that the automatic mechanism to merge those updates is not working anymore. Thus, I thought it would take 30 min. to be accepted, but it took more than that. It should be working now :slight_smile:

1 Like

It should be working without problems with DataFrames. With JuliaDB I am not so sure, I will take a look.

Thanks for this package, much appreciated.

Another request - can you decouple column alignment and header alignment? It is quite common in technical reports to leave the headers and sub-headers centered, while the columns are aligned as required. You allow us to override the alignment of cells with cell_alignment, but this doesn’t include the headers. Maybe add header_alignment, leaving alignment for the columns?

1 Like

Thanks! Good to know it is helping somehow :slight_smile:

Wow, nice catch! I did not realized that I missed this one :smiley: I think the best way is what you proposed. Let’s have a header_alignment and, if it is nothing, then it will follow the column alignment. Sounds good?

1 Like

Yes, that makes sense, especially as you can hide the headers and sub-headers; alignment should be the dominant attribute.