Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Well... I could not wait for response, so I wrote a simple implementation:

def latex_table(content, caption, label, header_rows = 1, header_columns = 0, position = 'htb'):
    code = """\\begin{table}[%s]
    \\centering
    \\caption{\\label{tab:%s} %s}
    """ % (position, label, caption)    
    code += '\\begin{tabular}{|%s|} \\hline\n' % '|'.join('c' for i in range(len(content[0])))    
    bold_format = '\\textbf{%s}'

    for line_no, line in enumerate(content):
        row_format_string = bold_format if line_no < header_rows else '%s'
        code += '        ' + ' & '.join([(bold_format if column_no < header_columns else row_format_string ) % i for column_no,i in enumerate(line)]) + ' \\\\ \\hline \n'    
    code += '    \\end{tabular}\n\end{table}\n'    
    return code

This code generates something similar to html.table output for latex. I'll be happy to know someone already wrote a better implementation.