Closed jo-fleck closed 8 months ago
Hi @jo-fleck !
Unfortunately, implementing this in text backend would require a lot of changes due to how horizontal lines are handled. Furthermore, I think it will be impossible to keep feature parity in the other backends.
Notice that, due to the default row spacing in terminals, double lines in text backend look strange:
┌──────────┬──────────┬───────────┐
├──────────┼──────────┼───────────┤
│ Col. 1 │ Col. 2 │ Col. 3 │
├──────────┼──────────┼───────────┤
├──────────┼──────────┼───────────┤
│ 0.969842 │ 0.55033 │ 0.14348 │
│ 0.477949 │ 0.736287 │ 0.438831 │
│ 0.482413 │ 0.780702 │ 0.0127566 │
└──────────┴──────────┴───────────┘
One good work around is to select a font that supports more UTF-8 box drawing and use characters with double horizontal lines as the table format as shown here: https://cloford.com/resources/charcodes/utf-8_box-drawing.htm
You can mix double lines and single lines using the keywords body_hlines
and body_hlines_format
.
Here is an example of my proposed work around:
using PrettyTables
tf = TextFormat(
up_right_corner = '╕',
up_left_corner = '╒',
bottom_left_corner = '╘',
bottom_right_corner = '╛',
up_intersection = '╤',
left_intersection = '╞',
right_intersection = '╡',
middle_intersection = '╪',
bottom_intersection = '╧',
column = '│',
row = '═',
hlines = [:begin, :header, :end],
vlines = :all,
)
body_hlines_format = ('├', '┼', '┤', '─')
A = rand(4, 4)
pretty_table(
A;
tf = tf,
body_hlines = [1, 2, 3],
body_hlines_format = body_hlines_format,
vlines = :none
)
The problem here is that the double lines will be placed only at the top, header, and bottom.
Many thanks for looking into this and for suggesting the workaround!
I wasn't aware of these particular characters so I am curious to work with them.
Many thanks for this great package @ronisbr !
It can be helpful to have double horizontal lines in a table, e.g. at the bottom or to separate different panels within the same table.
One (hopefully intuitive) way to implement this would be to repeat the row number in the
hlines
vector.So if you would like to have two lines after row n, you would simply include n twice in the
hlines
vector. Here is an example where the last line of the table is doubled:pretty_table(data; alignment = alig, header = head, hlines = [1, 10, 23, 33, :end, :end], backend = Val(:latex), highlighters = (hl_c2, hl_c3, hl_c4))
Could this be implemented without conflicting with other features?