[Tex/LaTex] Methods to edit column order in an existing LaTeX table

editorstables

What is the best way of editing an existing LaTeX table? I need to swap the order of two columns and can't think of an efficient way of doing this.

My table is a long creature of the following structure:

A &     -0.523 &      26.94 &     0.8243 &     0.0000 &     -12.67 \\
B &     -0.614 &      30.02 &     0.8509 &     0.0000 &     -13.12 \\
C &     -0.630 &      32.92 &     0.9254 &     0.0000 &     -21.45 \

I need to change the values so that it is:

A &     26.94 &      -0.523 &     0.8243 &     0.0000 &     -12.67 \\
(etc)

The thoughts that I had were to import it into Excel and to drag columns around, and then use the concatenate() function to produce the number & number structure. I feel like there might be a better way of doing this that I am unaware of.

Best Answer

Any editor with regular expression replace can easily swap columns. For example on the command line if tab.tex contains your input this regexp will swap column 2 and 3. (You may need more or less backslashes in the regexp depending on the command line shell in use)

 sed -e "s/^\([^\&]*\)\&\([^\&]*\)\&\([^\&]*\)/\1\3\2/" tab.tex 
A       26.94      -0.523 &     0.8243 &     0.0000 &     -12.67 \\
B       30.02      -0.614 &     0.8509 &     0.0000 &     -13.12 \\
C       32.92      -0.630 &     0.9254 &     0.0000 &     -21.45 \
Related Question