TexTables.jl icon indicating copy to clipboard operation
TexTables.jl copied to clipboard

Feature Request: Export DataFrame to LaTeX

Open jacobadenbaum opened this issue 6 years ago • 1 comments

This is a little tricky since each row needs an index. This can be solved by indexing by row number, but I think a lot of people who want this feature will not be happy with the row number showing up. So, this feature will need to come in two parts:

  1. Convert DataFrame to IndexedTable
  2. Update printing methods to allow the user to suppress printing the row index.

Neither of these is particularly hard. Just needs doing.

jacobadenbaum avatar Jul 22 '18 14:07 jacobadenbaum

I just needed this feature (DataFrame -> LaTeX-Table) and came up with this method. But I did not look too much into the package so there might be better implementations.

using DataFrames
import TexTables

function TexTables.regtable(df::DataFrames.DataFrame)
    colnames = names(df)
    cols = map(icol -> TexTables.TableCol(colnames[icol], collect(1:nrow(df)), df[!,colnames[icol]]), 1:ncol(df))
    TexTables.regtable(cols...)
end
to_tex(regtable(df)) # df is the DataFrame to export

lmh91 avatar Feb 07 '21 19:02 lmh91