# How to keep tables readable in code

What is the best practice for creating and updating tables in Latex? I am using Texmaker but I find it hard to update a table like adding entries or adding a column. I have to count entries which is kind of tedious. Is it better to first create a table in an excel type program and import it when finished? Example:

\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
Study & Year & Method & • & • & • & • & • & o & Result num. & Result \\
\hline
• & • & autor & autor et al & autor. & autor & autor\cite{autor} &

• Texmaker have a tabular wizard function that makes creating table easier, if this is what you are asking. – Francis Aug 7 '13 at 10:22
• Sort of related: tex.stackexchange.com/questions/49414/… – Torbjørn T. Aug 7 '13 at 10:36
• @Francis, thanks I know that one. But I think it cannot change existing tables. I am searching in literature and if I find a new result I want to add it to an existing table. So I have to add new rows and columns. – Lennart Aug 7 '13 at 12:26
• @Lennart, a good text editor is able to align text on specific characters. I use vim with the Align-plugin and align tables on the &-character and quite happy with that. Others may have even easier solutions. – schmendrich Aug 7 '13 at 14:58

I write my tables always in a pretty printed form to be able to recognize colums and rows in the LaTeX code.

My best practice is:

• I write one row in one line of my code (and if I need 200 characters)
• I write all & below each other so that I can see in the code the columns of my table. I keeo this structure even if I have to use the macros \multirow or \multicolumn.
• I write the end of a row (\\) below each other.
• I keep the table in my TeX document

An example:

\begin{tabular}{r@{:}l*{5}c}
\toprule
\multicolumn{1}{c}{}    &       & \multicolumn{5}{c}{Node ID}                                                          \\
\cmidrule{3-7}
\multicolumn{2}{c}{Date | Time} & 25             & 28             & 29             & 31              & 32              \\
\midrule
9/29/2007 00            &00     & \ding{108}     & \ding{108}     & \ding{108}     & \ding{108}      & \ding{108}      \\
9/29/2007 01            &00     & \ding{109}     & \ding{109}     & \ding{109}     & \ding{109}      & \ding{109}      \\
9/29/2007 23            &00     & \ding{108}     & \ding{108}     & \ding{109}     & \ding{108}      & \ding{109}      \\
\midrule
9/29/2007 23            &00     & \textbullet    & \textbullet    & \textbullet    & \textopenbullet & \textopenbullet \\
\midrule
9/29/2007 23            &00     & $\blacksquare$ & $\blacksquare$ & $\blacksquare$ & $\square$       & $\square$       \\
Columns: 1              & 2     & 3              & 4              & 5              & 6               & 7               \\
\bottomrule
\end{tabular}


Writing your table in this way allows you to change rows or columns better. With a little practice you will see it is usable ...

I write all my tables in this way.

I prefer to store large tables as CSV files and typescript them using pgfplotstable. There is a nice introduction to this package, and the simpler csvsimple, here: http://texblog.org/2012/05/30/generate-latex-tables-from-csv-files-excel/

• While this is good practice for some types of tables, it's not really what the asker needed. One should note that, when storing a table externally as CSV data, it's next to impossible to customize the format of the table (and forget merged cells). – Sean Allred Aug 7 '13 at 18:40

This is my code style for tables with many columns.

• Put the table in a separate file as follows. It can be either not-compilable file (without using standalone class) or compilable file (using standalone class). Advantages: (1) you can reuse your table for many projects, (2) your main input file will be more compact, easy to maintain, (3) when using standalone class, you can convert each table as a PDF that can be imported from within the main input file as an image with \includegraphics (don't forget use \usepackage{graphicx}), etc.
% not-compilable-table.tex
\begin{tabular}{|*{11}{c|}}
\hline
Study
& Year
& Method
& % 4
& % 5
& % 6
& % 7
& % 8
& % 9
& Result num.
& Result
\\\hline %------- Row End ---------
\LaTeX %Study
& 2012 %Year
& Brute Force %Method
& % 4
& % 5
& % 6
& % 7
& % 8
& % 9
& 99
& Good
\\\hline %------- Row End ---------
\end{tabular}


or

% compilable-table.tex
\documentclass[preview,border=12pt]{standalone}
\usepackage{array}

\begin{document}
\begin{tabular}{|*{11}{c|}}
\hline
Study
& Year
& Method
& % 4
& % 5
& % 6
& % 7
& % 8
& % 9
& Result num.
& Result
\\\hline %------- Row End ---------
\LaTeX %Study
& 2012 %Year
& Brute Force %Method
& % 4
& % 5
& % 6
& % 7
& % 8
& % 9
& 99
& Good
\\\hline %------- Row End ---------
\end{tabular}
\end{document}

• Arrange each entry prefixed with & (except for the first entry in each row, it is not prefixed with &) in a single line to ease data entry. At least, you no longer need horizontal scrolling. Adding column number or column name as a comment (%2, %3, %Study, %Year, etc, for example) for each entry will also ease inserting, editing data.

• Import the the table file using \input withing the main input file as follows.

% main-input-file.tex
\documentclass{article}
\usepackage{standalone}
\begin{document}
\input{<table-filename>}
\end{document}

• If you have any suggestion, please drop a comment. – kiss my armpit Sep 8 '13 at 3:37

I prefer aligning cells horizontally. I use a function in ViM (Vi Improved) called tabular. It can be found on github.

https://github.com/godlygeek/tabular

In my .vimrc I just add the following code to assign it to the F8 key and make it use the ampersand as a delimiter:

function! Tabularize( delim )
endfunction
map <F8> :call Tabularize( '/&' )


There is a nice video demonstration too:

http://vimcasts.org/episodes/aligning-text-with-tabular-vim/

You can also use Github's Atom from www.atom.io and install the atom-alignment package.

I set mine up like this:

Select the lines of the table and press ctrl alt a to execute on Windows or ctrl cmd a on MacOS.