Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Double lines #237

Closed
jo-fleck opened this issue Jan 30, 2024 · 3 comments
Closed

Feature: Double lines #237

jo-fleck opened this issue Jan 30, 2024 · 3 comments

Comments

@jo-fleck
Copy link

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?

@ronisbr
Copy link
Owner

ronisbr commented Feb 3, 2024

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.

@ronisbr
Copy link
Owner

ronisbr commented Feb 3, 2024

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
)
Captura de Tela 2024-02-03 às 11 59 08

The problem here is that the double lines will be placed only at the top, header, and bottom.

@jo-fleck
Copy link
Author

jo-fleck commented Feb 5, 2024

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.

@ronisbr ronisbr closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants