Tables¶
- class latexdocs.table.Table(table_spec=None, pos='h', *, columns=None, data=None, hlines=False, centering=True, caption=None, label=None, **kwargs)[source]¶
A class to handle tables using the tabular enviroment.
- Parameters
table_spec (str, Optional) – Controls alignment of the columns. If not provided, a default setting is inferred from the columns argument, is provided. Default is None.
pos (str, Optional) – Control the position of the table. Default is ‘h’.
columns (Iterable, Optional) – Column labels. Default is None.
data (Iterable, Optional) – The data content of the table. Default is None.
hline (bool, Optional) – Controls wether horizontal lines are to be added after rows or not. Only if data is provided at creation. Default is False.
centering (bool, Optional) – Controls wether the table is centralized or not. Default is True.
caption (str, Optional) – The caption of the table.
label (str, Optional) – The label of the table for later referencing.
Example
>>> from latexdocs import Document, Table >>> doc = Document() >>> columns = ['A', 'B', 'C', 'D'] >>> data = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) >>> doc.append(Table(data=data, columns=columns))
>>> table = Table('c c c c', pos='h', caption="This is a table.", label="table:tblref") >>> table.add_hline() >>> table.add_row(('Case', "Method 1", "Method 2", "Method 3")) >>> table.add_hline() >>> table.add_hline() >>> table.add_row((1, 50, 837, 321)) >>> table.add_row((2, 60, 437, 142)) >>> table.add_row((3, 70, 857, 708)) >>> table.add_row((4, 80, 172, 710)) >>> table.add_hline() >>> doc.append(table)
See also
- add_hline(*args, **kwargs)[source]¶
Adds a horizontal line to the table. The call is forwarded to
pylatex.table.Tabular.
- add_row(*args, **kwargs)[source]¶
Adds a new row to the table. The call is forwarded to
pylatex.table.Tabular.
- add_rows(data: Iterable, **kwargs)[source]¶
Adds multiple rows to the table. The call is forwarded to
pylatex.table.Tabular.
- add_empty_row()[source]¶
Adds an empty row to the table. The call is forwarded to
pylatex.table.Tabular.
- class latexdocs.table.TableX(table_spec=None, pos='h', *, columns=None, data=None, hlines=False, centering=True, caption=None, label=None, **kwargs)[source]¶
A class to handle tables using the tabularx enviroment.
Example
>>> from latexdocs import Document, TableX >>> doc = Document() >>> columns = ['A', 'B', 'C', 'D'] >>> data = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) >>> nD = data.shape[-1] >>> table_spec = r"|".join(nD * [r">{\centeringrraybackslash}X",]) >>> doc.append(TableX(table_spec, 'h!', data=data, columns=labels))
- __init__(table_spec=None, pos='h', *, columns=None, data=None, hlines=False, centering=True, caption=None, label=None, **kwargs)¶
Returns a LinkedDeepDict instance.
- Parameters
*args (tuple, Optional) – Extra positional arguments are forwarded to the dict class.
parent (LinkedDeepDict, Optional) – Parent LinkedDeepDict instance. Default is None.
root (LinkedDeepDict, Optional) – The top-level object. It is automatically set when creating nested layouts, but may be explicitly provided. Default is None.
locked (bool or NoneType, Optional) – If the object is locked, it reacts to missing keys as a regular dictionary would. If it is not, a new level and a new child is created (see the examples in the docs). A None value means that in terms of locking, the state of the object is inherited from its parent. Default is None.
**kwargs (tuple, Optional) – Extra keyword arguments are forwarded to the dict class.
- add_hline(*args, **kwargs)¶
Adds a horizontal line to the table. The call is forwarded to
pylatex.table.Tabular.
- add_row(*args, **kwargs)¶
Adds a new row to the table. The call is forwarded to
pylatex.table.Tabular.
- add_rows(data: Iterable, **kwargs)¶
Adds multiple rows to the table. The call is forwarded to
pylatex.table.Tabular.
- add_empty_row()¶
Adds an empty row to the table. The call is forwarded to
pylatex.table.Tabular.