py2latex.tables

Classes:

SubTable(tabular_data, *, caption[, label, …])

type tabular_data

Sequence[Sequence[Any]]

Functions:

add_longtable_caption(table[, caption, label])

Add a caption to a longtable.

longtable_from_template(tabular_data, *, caption)

Create a longtable with booktabs formatting.

multicolumn(cols, pos, text)

type cols

int

parse_column_alignments(colalign, colwidths, …)

type colalign

Optional[Sequence[Optional[str]]]

parse_hlines(nrows[, hlines])

type nrows

int

parse_vspace(ncols[, vspace])

type ncols

int

set_table_widths(table, widths)

Override the column widths (and also the column alignments) in a tabular environment, etc.

subtables_from_template(subtables, *, caption)

Create a series of subtables with booktabs formatting.

table_from_template(tabular_data, *, caption)

Create a table with booktabs formatting.

tabular_from_template(tabular_data, *[, …])

Create a tabular environment with booktabs formatting.

class SubTable(tabular_data, *, caption, label=None, headers=(), floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]

Bases: object

Parameters
  • tabular_data (Sequence[Sequence[Any]])

  • caption (str) – The caption for the table

  • label (Optional[str]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces Default None.

  • headers (Sequence[str]) – A sequence of column headers. Default ().

  • floatfmt (Union[str, Iterable[str]]) – The formatting of float values. Default "g". Default 'g'.

  • numalign (Optional[str]) – Default 'decimal'.

  • stralign (Optional[str]) – Default 'left'.

  • missingval (Union[str, Iterable[str]]) – Default ''.

  • showindex (Union[str, bool, Iterable[Any]]) – Default 'default'.

  • disable_numparse (Union[bool, Iterable[int]]) – Default False.

  • colalign (Optional[Sequence[Optional[str]]]) – Default None.

  • colwidths (Optional[Sequence[Optional[str]]]) – Sequence of column widths, e.g. 3cm. Values of None indicates auto width. Default None.

  • vlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified columns. -1 indicates a line should be inserted after the last column. If True a line will be inserted before every column, and after the last column. If False no lines will be inserted. Default False.

  • hlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified rows. -1 indicates a line should be inserted after the last row. If True a line will be inserted before every row, and after the last row. If False no lines will be inserted. Default False.

  • vspace (Union[Sequence[int], bool]) – If a sequence of integers extra space will be inserted before the specified row. -1 indicates a space should be inserted after the last row. If True a space will be inserted before every row, and after the last row. If False no spaces will be inserted. Default False.

  • raw (bool) – Whether latex markup in tabular_data should be unescaped. Default False. Default True.

  • footer (Optional[str]) – Optional footer for the table. Inserted as raw LaTeX. Default None.

add_longtable_caption(table, caption=None, label=None)[source]

Add a caption to a longtable.

Parameters
Returns

Return type

str

longtable_from_template(tabular_data, *, caption, label=None, headers=(), pos='htpb', floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]

Create a longtable with booktabs formatting.

Parameters
  • tabular_data (Sequence[Sequence[Any]])

  • caption (str) – The caption for the table

  • label (Optional[str]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces Default None.

  • headers (Sequence[str]) – A sequence of column headers. Default ().

  • pos (str) – The positioning of the table, e.g. "htp". Default 'htpb'.

  • floatfmt (Union[str, Iterable[str]]) – The formatting of float values. Default "g". Default 'g'.

  • numalign (Optional[str]) – Default 'decimal'.

  • stralign (Optional[str]) – Default 'left'.

  • missingval (Union[str, Iterable[str]]) – Default ''.

  • showindex (Union[str, bool, Iterable[Any]]) – Default 'default'.

  • disable_numparse (Union[bool, Iterable[int]]) – Default False.

  • colalign (Optional[Sequence[Optional[str]]]) – Default None.

  • colwidths (Optional[Sequence[Optional[str]]]) – Sequence of column widths, e.g. 3cm. Values of None indicates auto width. Default None.

  • vlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified columns. -1 indicates a line should be inserted after the last column. If True a line will be inserted before every column, and after the last column. If False no lines will be inserted. Default False.

  • hlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified rows. -1 indicates a line should be inserted after the last row. If True a line will be inserted before every row, and after the last row. If False no lines will be inserted. Default False.

  • vspace (Union[Sequence[int], bool]) – If a sequence of integers extra space will be inserted before the specified row. -1 indicates a space should be inserted after the last row. If True a space will be inserted before every row, and after the last row. If False no spaces will be inserted. Default False.

  • raw (bool) – Whether latex markup in tabular_data should be unescaped. Default False. Default True.

  • footer (Optional[str]) – Optional footer for the table. Inserted as raw LaTeX. Default None.

Returns

Return type

str

multicolumn(cols, pos, text)[source]
Parameters
  • cols (int) – The number of columms to span

  • pos (str) – Text alignment: * c for centered * l for flushleft * r for flushright

  • text (str)

Return type

str

parse_column_alignments(colalign, colwidths, vlines, ncols)[source]
Parameters
Return type

str

parse_hlines(nrows, hlines=False)[source]
Parameters
Return type

Tuple[bool, Sequence[int]]

parse_vspace(ncols, vspace=False)[source]
Parameters
Return type

Tuple[bool, Sequence[int]]

set_table_widths(table, widths)[source]

Override the column widths (and also the column alignments) in a tabular environment, etc.

Parameters
Returns

Return type

str

subtables_from_template(subtables, *, caption, label=None, pos='htpb')[source]

Create a series of subtables with booktabs formatting.

Parameters
  • subtables (Iterable[SubTable])

  • caption (str) – The caption for the table

  • label (Optional[str]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces Default None.

  • pos (str) – The positioning of the table, e.g. "htp". Default 'htpb'.

Returns

Return type

str

table_from_template(tabular_data, *, caption, label=None, headers=(), pos='htpb', floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]

Create a table with booktabs formatting.

Parameters
  • tabular_data (Sequence[Sequence[Any]])

  • caption (str) – The caption for the table

  • label (Optional[str]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces Default None.

  • headers (Sequence[str]) – A sequence of column headers. Default ().

  • pos (str) – The positioning of the table, e.g. "htp". Default 'htpb'.

  • floatfmt (Union[str, Iterable[str]]) – The formatting of float values. Default "g". Default 'g'.

  • numalign (Optional[str]) – Default 'decimal'.

  • stralign (Optional[str]) – Default 'left'.

  • missingval (Union[str, Iterable[str]]) – Default ''.

  • showindex (Union[str, bool, Iterable[Any]]) – Default 'default'.

  • disable_numparse (Union[bool, Iterable[int]]) – Default False.

  • colalign (Optional[Sequence[Optional[str]]]) – Default None.

  • colwidths (Optional[Sequence[Optional[str]]]) – Sequence of column widths, e.g. 3cm. Values of None indicates auto width. Default None.

  • vlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified columns. -1 indicates a line should be inserted after the last column. If True a line will be inserted before every column, and after the last column. If False no lines will be inserted. Default False.

  • hlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified rows. -1 indicates a line should be inserted after the last row. If True a line will be inserted before every row, and after the last row. If False no lines will be inserted. Default False.

  • vspace (Union[Sequence[int], bool]) – If a sequence of integers extra space will be inserted before the specified row. -1 indicates a space should be inserted after the last row. If True a space will be inserted before every row, and after the last row. If False no spaces will be inserted. Default False.

  • raw (bool) – Whether latex markup in tabular_data should be unescaped. Default False. Default True.

  • footer (Optional[str]) – Optional footer for the table. Inserted as raw LaTeX. Default None.

Returns

Return type

str

tabular_from_template(tabular_data, *, headers=(), floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None, no_lines=False, left_margin=True, right_margin=True)[source]

Create a tabular environment with booktabs formatting.

Parameters
  • tabular_data (Sequence[Sequence[Any]])

  • headers (Sequence[str]) – A sequence of column headers. Default ().

  • floatfmt (Union[str, Iterable[str]]) – The formatting of float values. Default "g". Default 'g'.

  • numalign (Optional[str]) – Default 'decimal'.

  • stralign (Optional[str]) – Default 'left'.

  • missingval (Union[str, Iterable[str]]) – Default ''.

  • showindex (Union[str, bool, Iterable[Any]]) – Default 'default'.

  • disable_numparse (Union[bool, Iterable[int]]) – Default False.

  • colalign (Optional[Sequence[Optional[str]]]) – Default None.

  • colwidths (Optional[Sequence[Optional[str]]]) – Sequence of column widths, e.g. 3cm. Values of None indicates auto width. Default None.

  • vlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified columns. -1 indicates a line should be inserted after the last column. If True a line will be inserted before every column, and after the last column. If False no lines will be inserted. Default False.

  • hlines (Union[Sequence[int], bool]) – If a sequence of integers a line will be inserted before the specified rows. -1 indicates a line should be inserted after the last row. If True a line will be inserted before every row, and after the last row. If False no lines will be inserted. Default False.

  • vspace (Union[Sequence[int], bool]) – If a sequence of integers extra space will be inserted before the specified row. -1 indicates a space should be inserted after the last row. If True a space will be inserted before every row, and after the last row. If False no spaces will be inserted. Default False.

  • raw (bool) – Whether latex markup in tabular_data should be unescaped. Default False. Default True.

  • footer (Optional[str]) – Optional footer for the table. Inserted as raw LaTeX. Default None.

  • no_lines (bool) – Whether to suppress horizontal lines in the table. Default False. Default False.

  • left_margin (bool) – Whether to include a margin to the left of the table. Default True. Default True.

  • right_margin (bool) – Whether to include a margin to the right of the table. Default True. Default True.

Returns

Return type

str