ronisbr / PrettyTables.jl

Print data in formatted tables.
MIT License
411 stars 39 forks source link

LaTeX table_type array #96

Open michakraus opened 3 years ago

michakraus commented 3 years ago

Would it be possible to add a table type array for LaTeX output? This should be fairly simple to implement, the idea being to replace \begin{tabular} ... \end{tabular} with \begin{array} ... \end{array} and \begin{table} ... \end{table} with a suitable and possibly customizable math environment, e.g., \begin{equation} ... \end{equation}, \[ ... \] or ```math ... ``` for markdown output.

I am currently capturing the PrettyTables output and doing those replacements by hand, e.g. for printing tab_arr the code looks like:

    strio = IOBuffer()
    pretty_table(strio, tab_arr,
                    backend = :latex,
                    vlines = [1],
                    hlines = [s],
                    noheader = true)
    tab_latex = String(take!(strio))

    tab_markdown = replace(tab_latex, "tabular" => "array")
    tab_markdown = replace(tab_markdown, "\\begin{table}" => "```math")
    tab_markdown = replace(tab_markdown, "\\end{table}" => "```")

    print(io, "text/markdown", tab_markdown)

While this works fine, it would be nice to have an in-package solution.

ronisbr commented 3 years ago

Hi @michakraus

This should be very easy to implement, and also very handy. Thanks for the suggestion 👍🏻

I just need to see how can I make everything work with respect to the headers, highlighters, etc., but I will implement this.

michakraus commented 3 years ago

Splendid! Thanks a lot!