9

I use excel2latex to generate tables from Excel. The issue is that excel2latex generates really horribly formatted code with extra spaces, misaligned, etc. Does anyone have another solution to creating tables from excel? Alternatively from R? It seems that typing the actual table out could be pretty cumbersome. Another solution might be to have a piece of software that would format the code that excel2latex generates... does something like this exist? I use notepad++ and TeXWorks to edit the code.

EDIT This is the error I get from running that script:

C:\Users\alchernyakov\Dropbox\beta_var\paper_sys_idio_vol\table_tex_files>perl indent.plx test.tex > formatted_test.tex
Bareword found where operator expected at indent.plx line 9, near "<title>latexindent"
    (Missing operator before latexindent?) syntax error at indent.plx line 5, near "html>"
Unrecognized character \xC2; marked by <-- HERE after at master <-- HERE near column 53 at indent.plx line 9.
Alex
  • 2,111
  • 5
    try @cmhughes's indent.plx link: http://tex.blogoverflow.com/2012/08/a-perl-script-for-indenting-tex-files/ –  Nov 06 '12 at 01:50
  • related latex-code-sniffer-and-or-beautifier (thanks for the plug @HarishKumar :) ) – cmhughes Nov 06 '12 at 04:19
  • The list: http://tex.stackexchange.com/questions/49414/comprehensive-list-of-tools-that-simplify-the-generation-of-latex-tables – krlmlr Nov 06 '12 at 08:40
  • Why do you want to edit the code after exporting it from Excel2LaTeX? – krlmlr Nov 06 '12 at 08:41
  • because most of the time excel2latex generates a fairly poor table and manual editing is required – Alex Nov 06 '12 at 15:31
  • @HarishKumar: the file suggested doesn't work on windows with ActivePerl... i end up writing my papers on a windows machine.. any ideas what the problem is? – Alex Nov 06 '12 at 15:58
  • If the tables are simple I prefer to insert empty columns in Excel myself which are Then filled with ampersands manually. – Uwe Ziegenhagen Nov 06 '12 at 18:46
  • 1
    @Alex: doesn't work is not good enough to get help? Please give some more details. It works for me. Please see my long comment as answer. Pl. try that way. I also used active perl. Please provide one of your tables so that we can try on that also. –  Nov 06 '12 at 22:31
  • @Alex: I just wonder -- what do you want to edit manually? Which particular features a table can have are missing? – krlmlr Nov 07 '12 at 09:08
  • @HarishKumar: posted above what the error is – Alex Nov 07 '12 at 15:29
  • @cmhughes: Will you please have a look at this error? Please. –  Nov 07 '12 at 22:06
  • @HarishKumar your answer is great (+1) :) can't think of a better way to describe the process... perhaps you could link to Paulo's great answer here: http://tex.stackexchange.com/questions/37610/how-to-make-the-rmligs-script-available-globally-on-windows – cmhughes Nov 07 '12 at 22:18
  • 1
    @Alex: You must not download directly https://github.com/cmhughes/latexindent.plx ! Go on it, then click on “indent.plx” and then download by clicking on the “Raw” button! Your error message comes from the HTML file you actually downloaded. – Speravir Nov 07 '12 at 22:30
  • @cmhughes Thank you. I think speravir has nailed the error. :-) –  Nov 07 '12 at 22:56
  • wow, this was stupid of me. sorry about that guys. – Alex Nov 07 '12 at 23:23

1 Answers1

6

This is not an exact answer but a reply to one of the comments above. (Can't have formatted code in comment)

the file suggested doesn't work on windows with ActivePerl... i end up writing my papers on a windows machine.. any ideas what the problem is?

First, we have to install perl -- either strawberry or active and the perl should be included in system path (important). For some more details pl refer to this question and answer

Then if your .tex file is in a folder c:\myfolder\myfile.tex (say), open command prompt and navigate to this folder typing

cd    cd myfolder

If you are on a different drive, other than C: as suggested by Speravir you can also type (instead of above lines)

cd /d c:\myfolder

to reach myfolder.

Ensure that the file indent.plx is also in the same folder (or include its path to the system variable). Now type

perl indent.plx myfile.tex > myfile-formatted.tex

and press Enter.

This will generate a new file called myfile-formatted.tex (which is formatted) in the same folder. A little example:

Before formatting:

\documentclass{article}


\begin{document}
  % Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{tabular}{rrr}

         1 &    1000000 &       This \\

         2 &        200 &       That \\

         3 &     300000 &       Here \\

         4 &     500000 &    My name \\

         5 &      20000 & Is it so? Then OK \\

         6 &         10 & This works. \\

\end{tabular}

   % Table generated by Excel2LaTeX from sheet 'Sheet1' and misaligned by me
\begin{tabular}{rrr}

1      &    1000000             &       This \\

2  &        200    &       That \\

  3 &300000 & Here \\

 4              &     500000                                 &    My name \\

  5 &      20000             & Is it so? Then OK \\

            6 &         10     & This works. \\

\end{tabular}

\end{document}

After formatting:

\documentclass{article}


\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{tabular}{rrr}

    1 & 1000000 & This              \\

    2 & 200     & That              \\

    3 & 300000  & Here              \\

    4 & 500000  & My name           \\

    5 & 20000   & Is it so? Then OK \\

    6 & 10      & This works.       \\

\end{tabular}

% Table generated by Excel2LaTeX from sheet 'Sheet1' and misaligned by me
\begin{tabular}{rrr}

    1 & 1000000 & This              \\

    2 & 200     & That              \\

    3 & 300000  & Here              \\

    4 & 500000  & My name           \\

    5 & 20000   & Is it so? Then OK \\

    6 & 10      & This works.       \\

\end{tabular}

\end{document}

Note:

As noted by @speravir:

You must not download directly https://github.com/cmhughes/latexindent.plx ! Go on it, then click on “indent.plx” and then download by clicking on the “Raw” button! Your error message comes from the HTML file you actually downloaded.

David Carlisle
  • 757,742
  • Harish Making one line from two: Replace cd\cd c:\myfolder with cd /d c:\myfolder (in one line, as I said). “My” version works also, if one is one a different drive first, “your” version not. – Speravir Nov 06 '12 at 22:39
  • But you can use “my” version always, also on the same drive. :-) – Speravir Nov 06 '12 at 23:11
  • @Speravir: You are right. In fact I hate the command prompt. Don't tell anybody ;-) –  Nov 06 '12 at 23:17
  • Oh, I will try. ;-) – Speravir Nov 06 '12 at 23:24