Texttable is a Python package that can create simple ASCII tables.
This package extends its functionality to allow the table to be directly output in Latex, removing the tedious copy and paste chore.
The Latex output matches the table design, and there are utilities for adding table captions, labels, and positions.
The single function latextable.draw_latex returns a formatted Latex string based on the provided table.
Aside from table, all arguments are optional.
draw_latex(table, caption=None, caption_short=None, caption_above=False, label=None, drop_columns=None,
drop_rows=None, position=None, use_booktabs=False):
table: Texttable table to be rendered in Latex.
caption: A string that adds a caption to the Latex formatting.
caption_short: A string that adds a short caption (used in the list of tables). Ignored if caption is None.
caption_above: If True, the caption will be added above the table rather than below it (default).
label: A string that adds a referencing label to the Latex formatting.
drop_columns: A list of column names that won't be in the Latex output.
Each column name must be in the table header.
drop_rows: A list of row indices that won't be in the Latex output.
Each row index must be in [0, number of rows - 1], where number of rows does not include the header.
position: A string that represents LaTex's float position of the table.
For example 'ht' results in the float position [ht].
use_booktabs: Whether to override the table formatting with booktabs (https://ctan.org/pkg/booktabs?lang=en).
If true, the texttable formatting is ignored, and instead the default booktabs style is used.
This overrides the border, vertical lines, and horizontal lines.
Note the booktabs package will need to be included in your Latex document (\\usepackage{booktabs}).
Defaults to false.
return: The formatted Latex table returned as a single string.
请发表评论