# Which text editor to make tables scripts human readable

Suppose I want to edit a table

moon & 456456456423423534 &  2342523
sun  &             234324 &     3453


You see I have to enter a lot of spaces manually to align stuff. It is ok for a small table but for a large table this is inefficient.

I wonder there there is an editor that I can easily write tables in human readable script. I am familiar with vim and Ultraedit though I don't know which functionality specifically I should use. Perhaps there are software better than vim and Ultraedit for this purpose.

-
Sorry, let me be specific. I understand how to do it in vim. But suppose my work place doesn't have vim , but only ultraedit. Is there a way to do this in using Ultraedit? –  Zwingli Tannenbaum Mar 1 '12 at 15:22
No vim on the workstation? Change the employer! –  Marco Mar 1 '12 at 15:39
New question, how to do this in Kile? –  Zwingli Tannenbaum Mar 6 '12 at 4:33

I am very happy with vim and the tabular plugin. To align the table, place the cursor anywhere inside the (nonaligned) table and type :Tabularize /&. The result is a nicely aligned table.

Before:

moon&456456456423423534&2342523
sun&234324&3453


Then a :Tabularize /&, after:

moon & 456456456423423534 & 2342523
sun  & 234324             & 3453


If you need this often, you can assign a custom shortcut for this.

-
You beat me by 10 seconds. :) Nice plugin. There's a video tutorial on how to use it. :) –  Paulo Cereda Mar 1 '12 at 14:43
Thank you, can you tell me how to assign a this function as 'control-E' in vim. I forgot the syntax of keyboard shortcut in vimrc –  Zwingli Tannenbaum Mar 1 '12 at 15:07
@ZwingliTannenbaum You can assign a mapping in command mode with :nmap <Leader>at :Tabularize /&<CR> or in insert mode with :imap <Leader>at <ESC>:Tabularize /&<CR>i. I choose <Leader> (which is the backslash by default) to avoid interference with the scrolling (<CTRL>-e). at simply stands for “align table”, but you are free to pick another mnemonic. –  Marco Mar 1 '12 at 15:33
Sorry I have a lot of trouble in installing tabularize.vim as a plugin. I use Mac and Windows and Linux, I want to install tabuliarze.vim on all three, the supposedly autoloaded plugin directory just doesn't get autoloaded, I tried a whole bunch different directories but it just doesn't get loaded, is there a way to "force load" tabularize.vim, say put in vimrc file . "loadplugin /.vim/plugin/after/tabularize.vim" –  Zwingli Tannenbaum Mar 1 '12 at 16:01
@ZwingliTannenbaum What about trying either of then and check which one works? A try will not nuke your system. –  Marco Mar 1 '12 at 20:11

In emacs, AUCTeX includes align.el, which provides the command align-current: select the content of the table, and run M-x align-current, and it will auto-align the columns, producing the same result as in @Marco's answer

-
Sorry I don't use EMACS, how to do it in VI or ultraedit? –  Zwingli Tannenbaum Mar 1 '12 at 14:52
@ZwingliTannenbaum, I don't use VI or ultraedit :) Marco's presented one approach in vim, and your question just asked if there was some editor that did table-editing well. If vi or ultraedit are actually requirements in your question, you may want to edit it to clarify that a bit. –  Ben Lerner Mar 1 '12 at 15:03

On a mac

With Texshop

1) You can use a matrix panel

2) Remark from Alan Munn

In TeXShop you can also use a spreadsheet for the cells and then paste them with Paste Spreadsheet Cells from the Macros menu

With TextMate

1) you begin with a selection like this

  12 15 13
1 2 3


then you select "convert selection to table" or you type "shift control command T" to get

\begin{tabular}{c}
\hline
12 15 13\\
\hline
1 2 3\\
\hline
\end{tabular}


2) you can use "Create Table" and you give the number of rows and column then with TAB you can move from cell to cell

-
In TeXShop you can also use a spreadsheet for the cells and then paste them with Paste Spreadsheet Cells from the Macros menu. –  Alan Munn Mar 3 '12 at 14:18
@AlanMunn Now I no longer use TexShop also I had forgotten this possibility. I add your remark in my answer –  Alain Matthes Mar 3 '12 at 15:08
How to do this in WinEDT? –  Zwingli Tannenbaum Mar 3 '12 at 18:42
I don't know WinEdt sorry :( –  Alain Matthes Mar 3 '12 at 19:50

Disclaimer: I also use the Tabular plugin in Vim (see Marco's answer). :)

There's a similar Vim plugin called Align which behaves pretty much the same as Tabular.

moon & 456456456423423534 & 2342523
sun & 234324 & 3453


By issuing :Align &:

moon & 456456456423423534 &  2342523
sun  &             234324 &     3453


You can also use multiple separators at once, e.g, :Align = + - \* /.

There's also another command called AlignCtrl which has more options, including text alignment (left, right, center). By using the > operator, you can right-justify the table just like the question example.

Lots of examples can be found in the GitHub repo.

-

1. LaTable and Tablas

On Windoz, you can use LaTable

LaTable at CTAN

or Tablas

Tablas 3.0

LaTable may have some small quirks under Win7. Both programs produce LaTex code to copy and paste into a LaTex manuscript, or saved as separate files, which you can input in your manuscript.

2. CSVed and uniCSVed

Sam Francke has written two very potent programs for manipulating CSV-files. You can easily adopted those to a LaTex workflow. Have a look at the home page of CSVed and uniCSVed

CSVed is the most feature rich of the two programs. You can manipulate CSV-files in more of less every thinkable ways. CSVed is especially capable for editing CSV-files with lot of records, which you can inputas table body in a longtable or tabular environment. The author is also looking into the possibility to add options to save to LaTex format (also an option to automatically escape LaTex special characters). Limitation: You cannot save in a UTF8 format (uniCSVedit can). Until the export filter is ready, you have to input the file between suitable table environments in your manuscript, after you have added \\. On the other hand, you can use Nicola Talbot's datatool-package to merge the resulting CSV-file into a LaTex table.

uniCSVed has less features than CSVed, but you can save your file in Unicode (also without BOM). Links to uniCSVed are:

uniCSVed can save the CSV-files in a format usable for LaTex (i.e. with & and \\).

1. Open a file to convert (has to be UTF8 with or without BOM), or create a new file
2. Go to TAB Modify 2 and add the suffix \\ to the last column
3. Go to first TAB and change separator at Other &
4. Open menu File - Encode in and select UTF-8 wo BOM

TeXmaker

Also, the free cross-platform LaTeX editor TeXmaker has a very capable Table Wizard. But as most Wizards, this is a one-shot. When you have closed the Wizard, you are left with the usual LaTeX-code in the manuscript. It cannot be reloaded in the Wizard for further editing.

-
How to do this in WinEDT? –  Zwingli Tannenbaum Mar 3 '12 at 18:42
@Zwingli Tannenbaum. The author of Tablas has some WinEDT macros on his homepage. informatica.us.es/~calvo/prog/macros.zip –  Sveinung Mar 3 '12 at 19:11
latable and tablas work with linux/wine! small but excellent for the job. –  alfC Mar 6 '12 at 22:03

When I studied Astronomy over 20 years ago knowledge of Unix was assumed.

$more myfilename.csv moon & 456456456423423534 & 2342523 sun &234324 & 3453  and now $ cat myfilename.csv | column  -t
moon  &  456456456423423534  &  2342523
sun   &  234324              &  3453


With little fiddling you can easily align columns to the right!

-

OpenOffice.org allows to use any character as column separator for CSV (comma-separated values file format), so if you write large tables, you can put their data in a separate file and edit it there.

Here is some how-to on this functionality.

-

The next function uses the tabular plugin in Vim to automatically align table columns as you type them (once you have typed the first row):

function! s:ealign()
let p = '^.*&\s.*\$'
if exists(':Tabularize') && getline('.') =~# '^.*&' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^&]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*&\s*\zs.*'))
Tabularize/&/l1
normal! 0
call search(repeat('[^&]*&',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction


To make it work only with tex files add the following to your vimrc file:

augroup ft_tex
au!
au Filetype tex inoremap <buffer> <silent> & &<Esc>:call <SID>ealign()<CR>a
augroup END

-

For winedt, there is a plugin: TeXtab. You can find the installtion instructions in the page itself. To quote from there:

The macro formats selected lines with respect to & and \\. It disregards \&

There are two ways to format the selected lines:

formatting with blanks leading and trailing & and \\:

aaaaaaaaaa&bb\&bbbbbb&ccccccc&&\\
eeee&fffff&gggg&hh&ii&jjjjjjj&kkkkkk\\


will be changed to

aaaaaaaaaa & bb\&bbbbbb & ccccccc &    & \\
eeee       & fffff      & gggg    & hh & ii  & jjjjjjj & kkkkkkkk \\


formatting without blanks between text and separators:

aaaaaaaaaa&bb\&bbbbbb&ccccccc&  &\\
eeee      &fffff     &gggg   &hh&ii &jjjjjjj&kkkkkk\\


How do you use the macro:

Select full lines containing lines of a tabular block. Choose in menu Edit one of the menu item Format TeX-Tables with blanks or Format TeX-Tables without blanks (ALT e x or ALT e o).

-
This one also answers the question Kile vs WinEDT vs TexShop. See my answer there. –  karlkoeller Jun 6 '13 at 5:26