taldcroft/asciitable — Issue #23: Units in AASTex tables
Author: deduBas8
Created: 2011-10-13 13:27:58+00:00
State: open

Hi Tom.

I am interested in adding units to an AASTex deluxetable. The standard, at least for AJ & ApJ, is to include the units as the second row of the table. For example:

http://aas.org/journals/authors/common_instruct#_Toc6

For a deluxetable, the way I have seen everybody do this is to add a second row of units to the \tablehead{}.

An example table of this is

```
\begin{deluxetable}{cc}
\tablehead{\colhead{col1} & \colhead{col2}\\
\colhead{cm} & \colhead{km}}
\startdata
0 & dog \\
1 & cat \\
2 & pig \\
\enddata
\end{deluxetable}
```

Where col1 has units of cm and col2 has units of km. I think the easiest want to achieve this for the deluxetable is to allow an additional optional entry 'units' to the latexdict. If 'units' is passed, it gets joined into the \tablehead{} with a newline separating the names form the units.

To accomplish this, I modified the file latex.py by adding at line 291 the following code.

```
if 'units' in self.latex.keys():
if len(self.latex['units']) != len(self.cols):
raise Exception("There must be only as many units as there are columns.")
tablehead += r'\\'+ '\n' + ' & '.join([r'\colhead{' + u + '}' for u in self.latex['units']])
```

With this addition, I can successfully create the example table using the following lines of code

```
import asciitable

table = {
r'col1': [0, 1, 2],
'col2': ['dog', 'cat', 'pig']
}

asciitable.write(table, sys.stdout, Writer=asciitable.AASTex,
names=[r'col1','col2'],
latexdict = dict(units=['cm', 'km']))
```

I am sorry, but my git skills are lacking, so I am unable to submit a pull request. But would you be willing to incorporate this new feature into your code? Or can you think of a better way to implement this.

All the best,

Joshua