pylatex.table¶
This module implements the class that deals with tables.
-
class
Tabular(table_spec, data=None, pos=None, *, row_height=None, col_space=None, width=None, booktabs=None, **kwargs)[source]¶ Bases:
pylatex.base_classes.containers.EnvironmentA class that represents a tabular.
Parameters: - table_spec (str) – A string that represents how many columns a table should have and if it should contain vertical lines and where.
- pos (list) –
- row_height (float) – Specifies the heights of the rows in relation to the default row height
- col_space (str) – Specifies the spacing between table columns
- booktabs (bool) – Enable or disable booktabs style tables. These tables generally
look nicer than regular tables. If this is
Noneit will use the value of thebooktabsattribte from theactiveconfiguration. This attribute isFalseby default. - width (int) – The amount of columns that the table has. If this is
Noneit is calculated based on thetable_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.
References
-
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
-
omit_if_empty= False¶
-
class
Tabularx(*args, width_argument=NoEscape(textwidth), **kwargs)[source]¶ Bases:
pylatex.table.TabularA class that represents a tabularx environment.
Parameters: width_argument – The width of the table. By default the table is as wide as the text. -
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
-
omit_if_empty= False¶
-
-
class
MultiColumn(size, *, align='c', color=None, data=None)[source]¶ Bases:
pylatex.base_classes.containers.ContainerA class that represents a multicolumn inside of a table.
Parameters: - size (int) – The amount of columns that this cell should fill.
- align (str) – How to align the content of the cell.
- data (str, list or
LatexObject) – The content of the cell. - color (str) – The color for the MultiColumn
-
class
MultiRow(size, *, width='*', color=None, data=None)[source]¶ Bases:
pylatex.base_classes.containers.ContainerA class that represents a multirow in a table.
Parameters: - size (int) – The amount of rows that this cell should fill.
- width (str) – Width of the cell. The default is
*, which means the content’s natural width. - data (str, list or
LatexObject) – The content of the cell. - color (str) – The color for the MultiRow
-
class
Table(*, position=None, **kwargs)[source]¶ Bases:
pylatex.base_classes.float.FloatA class that represents a table float.
Parameters: position (str) – Define the positioning of a floating environment, for instance 'h'. See the references for more information.References
-
add_caption(caption)[source]¶ Add a caption to the float.
Parameters: caption (str) – The text of the caption.
-
omit_if_empty= False¶
-
-
class
Tabu(table_spec, data=None, pos=None, *, row_height=None, col_space=None, width=None, booktabs=None, spread=None, to=None, **kwargs)[source]¶ Bases:
pylatex.table.TabularA class that represents a tabu (more flexible table).
Parameters: - table_spec (str) – A string that represents how many columns a table should have and if it should contain vertical lines and where.
- pos (list) –
- row_height (float) – Specifies the heights of the rows in relation to the default row height
- col_space (str) – Specifies the spacing between table columns
- booktabs (bool) – Enable or disable booktabs style tables. These tables generally
look nicer than regular tables. If this is
Noneit will use the value of thebooktabsattribte from theactiveconfiguration. This attribute isFalseby default. - spread (str) – Specifies the Tabu table should add a given amount of ‘padding’ to the width of the table. This should be a latex dimension; for example: “0 pt” or “1in”
- to (str) – Specifies the Tabu table should extend to a given width. This should be a latex dimension; for example ‘4in’
- width (int) – The amount of columns that the table has. If this is
Noneit is calculated based on thetable_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.
References
-
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
-
omit_if_empty= False¶
-
class
LongTable(table_spec, data=None, pos=None, *, row_height=None, col_space=None, width=None, booktabs=None, **kwargs)[source]¶ Bases:
pylatex.table.TabularA class that represents a longtable (multipage table).
Parameters: - table_spec (str) – A string that represents how many columns a table should have and if it should contain vertical lines and where.
- pos (list) –
- row_height (float) – Specifies the heights of the rows in relation to the default row height
- col_space (str) – Specifies the spacing between table columns
- booktabs (bool) – Enable or disable booktabs style tables. These tables generally
look nicer than regular tables. If this is
Noneit will use the value of thebooktabsattribte from theactiveconfiguration. This attribute isFalseby default. - width (int) – The amount of columns that the table has. If this is
Noneit is calculated based on thetable_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.
References
End the table foot which will appear on every page.
End the table foot which will appear on the last page.
-
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
-
omit_if_empty= False¶
-
class
LongTabu(table_spec, data=None, pos=None, *, row_height=None, col_space=None, width=None, booktabs=None, spread=None, to=None, **kwargs)[source]¶ Bases:
pylatex.table.LongTable,pylatex.table.TabuA class that represents a longtabu (more flexible multipage table).
Parameters: - table_spec (str) – A string that represents how many columns a table should have and if it should contain vertical lines and where.
- pos (list) –
- row_height (float) – Specifies the heights of the rows in relation to the default row height
- col_space (str) – Specifies the spacing between table columns
- booktabs (bool) – Enable or disable booktabs style tables. These tables generally
look nicer than regular tables. If this is
Noneit will use the value of thebooktabsattribte from theactiveconfiguration. This attribute isFalseby default. - spread (str) – Specifies the Tabu table should add a given amount of ‘padding’ to the width of the table. This should be a latex dimension; for example: “0 pt” or “1in”
- to (str) – Specifies the Tabu table should extend to a given width. This should be a latex dimension; for example ‘4in’
- width (int) – The amount of columns that the table has. If this is
Noneit is calculated based on thetable_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.
References
-
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
End the table foot which will appear on every page.
End the table foot which will appear on the last page.
-
foot= False¶
-
header= False¶
-
lastFoot= False¶
-
omit_if_empty= False¶
-
class
LongTabularx(*args, width_argument=NoEscape(textwidth), **kwargs)[source]¶ Bases:
pylatex.table.Tabularx,pylatex.table.LongTableA class that represents a long version of the tabularx environment.
This uses the
ltablexpackage. This package modifies thetabularxenvironment so that it can be spread over multiple pages. This has the sideeffect that using this class in a document spreads allTabularxelements in that document over multiple pages as well.Parameters: width_argument – The width of the table. By default the table is as wide as the text. -
add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]¶ Add a horizontal line to the table.
Parameters:
-
add_row(*cells, color=None, escape=None, mapper=None, strict=True)[source]¶ Add a row of cells to the table.
Parameters: - cells (iterable, such as a
listortuple) – There’s two ways to use this method. The first method is to pass the content of each cell as a separate argument. The second method is to pass a single argument that is an iterable that contains each contents. - color (str) – The name of the color used to highlight the row
- mapper (callable or
list) – A function or a list of functions that should be called on all entries of the list after converting them to a string, for instance bold - strict (bool) – Check for correct count of cells in row or not.
- cells (iterable, such as a
End the table foot which will appear on every page.
End the table foot which will appear on the last page.
-
foot= False¶
-
header= False¶
-
lastFoot= False¶
-
omit_if_empty= False¶
-
-
class
ColumnType(name, base, modifications, *, parameters=None)[source]¶ Bases:
pylatex.base_classes.command.UnsafeCommandA class representing a new column type.
It uses the
\newcolumntypecommand, for a thorough explanation see this StackExchange question.Parameters: - name (str) – The name of the new column type (a single letter)
- base (str) – The name of the column type that the new one is based on (a single letter)
- modifications (str) – The modifications to be made to the base column type
- parameters (int) – The number of # parameters inside the modifications string, if this
is
Nonethis is calculated automatically.