Skip to content

Instantly share code, notes, and snippets.

@astrolitterbox
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrolitterbox/8e92f27651608162bc06 to your computer and use it in GitHub Desktop.
Save astrolitterbox/8e92f27651608162bc06 to your computer and use it in GitHub Desktop.
Rendering a LaTeX table (Astronomy and Astrophysics format) in Python
from __future__ import division
#A decently-looking table in A&A long table format (http://www.aanda.org/author-information/latex-issues/latex-examples#large_tables)
#all the data columns are provided as lists, selected from a database. I cut that part out for clarity.
ofile = open('texts/datatable.tex', 'w')
ofile.write('\documentclass[onecolumn, 11pt]{aa}')
ofile.write('\usepackage{array}\n')
ofile.write('\pagestyle{empty}\n')
ofile.write('\setlength\extrarowheight{4pt}\n')
ofile.write('\setlength\LTleft{-0.5cm}\n')
ofile.write('\\'+'begin{document}\n')
ofile.write('\\'+'begin{longtable}{|p{0.5cm}p{2.5cm}p{2cm}p{1.5cm}p{1cm}p{1cm}p{1.5cm}p{1.7cm}p{1.2cm}p{2.5cm}|}\n')
ofile.write('\\'+'caption{ Main properties of the TF sample galaxies. A machine-readable version is available at ...}'+'\\\\\hline\n')
ofile.write('\\'+'bf{No.}&'+'\\'+'bf{Name}&'+'\\'+'bf{Morphology}&'+'\\'+'bf{z}&'+'\\'+'bf{M$_r$}&'+'\\'+'bf{$\Delta$ M$_r$}&'+'\\'+'bf{log($v_{circ}$)}&'+'\\'+'bf{$\Delta$log(v$_{circ})$}&'+'\\'+'bf{log(M$_*$)}&'+'\\'+'bf{V$_{max}$}\\\\\hline\n')
for i, galaxy in enumerate(califa_ids_list):
print galaxy, names[i]
item = str(i+1)+"&"+str(names[i]) + "&" +str(morph[i])+str(subtype[i])+ "&" +str(round(z[i], 3)) + "&" +str(round(absMag[i], 2)) + "&" +str(round(absMagErr[i], 2)) + "&" +str(round(log_vel[i], 2)) + "&" +str(round(vel_err[i], 2))+ "&" +str(round(stMass[i], 2))+ "&" +str(round(weights[i], 7))
ofile.write(item+'\\\\'+'\n')
ofile.write('\\hline\n')
ofile.write('\end{longtable}\n')
ofile.write('\end{document}\n')
ofile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment