It’s not clear from the docs how to hcat tables.
If you mean to concat the arrays I’m passing as input, then I think that could be a good work around. But the two arrays have different shapes and I would end up with some zeros at certain locations ( not convenient but manageable).
Will try that for now, thanks.
Yes, the only way I see to make this work now is to hcat
the arrays as @mkborregaard told. It will be really a huge modification to allow printing n-tables side by side because of how the printing system works.
If you really think this is a important feature to have, then, please, open an issue on Github.
Can you get the string representations and manipulate those?
Exactly. Should be pretty simple to split the strings on '\n'
and then pad whichever array is shorter with strings of spaces of the length of the rest of the elments of the array. Then you can just smash those two arrays of strings together and use join
.
Di you find a solution ? I have the same needs for a collection of practice sessions.
The Julia output is done via prettytables but I would like to get a latex output to be inserted in my latex manual.
We now have HTML support in PrettyTables (although needs some improvements), and LaTeX support should come next
Great! I was trying something like:
pretty_table(df) |> x->latexify(x,env=:table)
where df
is a dataframe, but no luck…
Is the plan to translate directly to \LaTeX, or go via something like latexify
?
I look forward to this! If I can, say, set up data in csv files and import them into, say, dataframes, and turn them into \LaTeX tables, that would be really nice.
It would also be great if one has the option to choose between simple one page tables, and multi page tables (for, say, thermodynamic data).
Anyway, great work.
My actual plan is to provide a native translation to LaTeX like the HTML backend.
Good! This should be quite easy (I think) when the backend is done.
Thanks!
For a more low-level approach, there is
I wrote a very basic function to quickly duplicate the prettytables output with a latex one.
Just in case it could be useful, here is the code
Summary
using Formatting
function format_string(a::String)
sa=replace(a,"_"=>"\\_")
"\\texttt{"*sa*"}"
end
format_string(a::Float64) = format_string(sprintf1("%5.3E",a))
format_string(a) = format_string(string(a))
function latex_table(table,header)
result=Vector{String}()
nrows,ncols=size(table)
push!(result," \\begin{tabular}{"*repeat("l",ncols)*"}")
push!(result,"\\toprule")
line=""
for j in 1:ncols
line=line*format_string(header[j])
if j!=ncols
line*="&"
else
line*="\\\\"
end
end
push!(result,line)
push!(result,"\\midrule")
# push!(result,line)
for i=1:nrows
line=""
for j in 1:ncols
line=line*format_string(table[i,j])
if j!=ncols
line*="&"
else
line*="\\\\"
end
end
push!(result,line)
end
push!(result,"\\bottomrule")
push!(result," \\end{tabular}")
for rows in result
println(rows)
end
result
end
Would it be simple to change floating point numbers, say 3.215E-01
, to math notation like 3.215\cdot 10^{-1}, as an option?
I am not sure that this is what you had in mind… I tend to prefer the previous one reminding me the good old F77 output
Summary
function format_string(a::Float64)
sa=sprintf1("%5.3E",a)
sa=replace(sa,"E"=>"\\cdot 10^{")
sa*="}"
sa=replace(sa,"\\cdot 10^{+00}"=>"")
sa=replace(sa,"{+0"=>"{")
sa=replace(sa,"{+"=>"{")
sa=replace(sa,"{-0"=>"{-")
"\$\\mathtt{$sa}\$"
end
Anyway, the code must be considered as a quick&dirty workaround helping me wait until the actual PrettyTables latex output is ready
Looks good. At least, a nice option. (similar for 32bit? 1.3f-2, etc…?)
Sure: it should be straightforward to adapt this format function to your needs. It is also probable that Latexify.jl or Formatting.jl provides a more general solution for math notations.
I am wondering how can we support LaTeX in PrettyTables.jl. Should it use the default tabular
environment or the more advanced tabularx
environment?
There is a Stata package for making nice latex tables from arbitrary matrices called frmttable. I used it a lot in my last job and think it’s a good place to look for implementation.
To my knowledge, longtable
is the only one that will play nice with page breaks; https://github.com/tpapp/LaTeXTabulars.jl/blob/master/src/LaTeXTabulars.jl#L198.
OK, I can add an option to select which environment the user wants and support tabular
and longtable
.
Multiple, nested headers would probably the pie-in-the sky ideal functionality to see in a tables package. But it would probably be far too much to implement in a first pass at latex output.
Indeed, I have tried to implement this feature for text output (https://github.com/ronisbr/PrettyTables.jl/issues/12). However, in that case, it is very difficult since you need to take care of the intersections. In LaTeX it will be much easier, but I think it is better to have a initial, simple version first