9

I know there are tools to export excel tables to latex, but what about the other way around? I get a lot of latex tables from functions in R (e.g.: texreg) that aren't perfectly customizable via the code, and need some editing. For example, I'll have variables like T:X and X:T as separate rows, based on how whatever model function interpreted an interaction expansion. I'd like to be able to input a tabular object and get .csv-like table, which I could then edit and re-export (using calc2latex in my case).

Anything like this exist?

8

Far from perfection, but for a document with a single table you can use detex and then replace & by , and delete empty lines. In Linux you can use some tools as grep and sed for this. The first line of the table is then the columns types, so you can delete manually or with some tool like tail. Example command line:

detex file.tex | grep -v '^$' | tail -n+2  | sed 's/&/,/g' > file.csv

Example input file.tex:

\documentclass{article}
\begin{document}
\begin{tabular}{llll}
    11 & 12 & 13 & 14\\
    21 & 22 & 23 & 24\\
    31 & 32 & 33 & 34\\
    41 & 42 & 43 & 44\\
\end{tabular}
\end{document}

Ouput (file.csv):

    11 , 12 , 13 , 14
    21 , 22 , 23 , 24
    31 , 32 , 33 , 34
    41 , 42 , 43 , 44
1

Here is another workaround, if you have Excel or a similar application, and you can manage to make a LaTeX file that contains only the table: convert the LaTeX file using pandoc to HTML, as follows:

pandoc -o output.html input.tex

Then, import the resulting HTML table into Excel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.