PrettyTables.jl
PrettyTables.jl copied to clipboard
[FR]: maximum horizontal size of columns
Currently I am working with the latex backend and if entries get too long they don't fit the page. Thus it would be good to say, e.g. break lines if they exceed 3cm or similar.
I don't know how useful this would be for other backends.
Hi @BeastyBlacksmith
Hum, it seems interesting! The problem is: I have no idea how to get the size of an entry.
One workaround should be changing the type of the column to p
with a specific size. We need to think about a good API to do this. The implementation should be easy. Any ideas?
I think we could extend alignment
to accept things like :p => "3cm"
It would not be nice because it will change the type of alignment
. It is a keyword that is passed to all backends as a Vector{Symbol}
. In this case, we might have a performance problem due to type instabilities.
an alternative would be to introduce a new keyword column_widths
being a Vector{String}
Yes, it can be done! column_widths
is not something common to all backends. What it should contain?
So, I would map
pretty_table(df, backend = Val(:latex), alignment = :l, column_widths = "3cm") # \begin{tabular}{p{3cm}p{3cm}...}
pretty_table(df, backend = Val(:latex), alignment = :l, column_widths = ["4em", ""]) # \begin{tabular}{lp{4em}}
pretty_table(df, backend = Val(:latex), alignment = :r, column_widths = ["4em", ""]) # error, since p is left aligned
Does that make sense?
Yes, seems good! I will just change the name to columns_width
to keep it equal as in text backend.
+1 for this! As a very hacky workaround, I am doing
# piracy
function PrettyTables._latex_alignment(s::Symbol)
if (s == :l) || (s == :L)
return "l"
elseif (s == :c) || (s == :C)
return "c"
elseif (s == :r) || (s == :R)
return "r"
elseif s == :p2cm
return "p{2cm}"
else
error("Invalid LaTeX alignment symbol: $s.")
end
end
and then passing :p2cm
as my alignment.