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.Environment

A 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 None it will use the value of the booktabs attribte from the active configuration. This attribute is False by default.
  • width (int) – The amount of columns that the table has. If this is None it is calculated based on the table_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:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
add_empty_row()[source]

Add an empty row to the table.

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 list or tuple) – 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.
omit_if_empty = False
class Tabularx(*args, width_argument=NoEscape(textwidth), **kwargs)[source]

Bases: pylatex.table.Tabular

A 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_empty_row()[source]

Add an empty row to the table.

add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]

Add a horizontal line to the table.

Parameters:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
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 list or tuple) – 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.
omit_if_empty = False
class MultiColumn(size, *, align='c', color=None, data=None)[source]

Bases: pylatex.base_classes.containers.Container

A 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.Container

A 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.Float

A 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.Tabular

A 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 None it will use the value of the booktabs attribte from the active configuration. This attribute is False by 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 None it is calculated based on the table_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.

References

add_empty_row()[source]

Add an empty row to the table.

add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]

Add a horizontal line to the table.

Parameters:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
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 list or tuple) – 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.
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.Tabular

A 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 None it will use the value of the booktabs attribte from the active configuration. This attribute is False by default.
  • width (int) – The amount of columns that the table has. If this is None it is calculated based on the table_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.

References

header = False[source]
foot = False[source]
lastFoot = False[source]
end_table_header()[source]

End the table header which will appear on every page.

End the table foot which will appear on every page.

End the table foot which will appear on the last page.

add_empty_row()[source]

Add an empty row to the table.

add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]

Add a horizontal line to the table.

Parameters:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
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 list or tuple) – 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.
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.Tabu

A 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 None it will use the value of the booktabs attribte from the active configuration. This attribute is False by 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 None it is calculated based on the table_spec, but this is only works for simple specs. In cases where this calculation is wrong override the width using this argument.

References

add_empty_row()[source]

Add an empty row to the table.

add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]

Add a horizontal line to the table.

Parameters:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
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 list or tuple) – 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.

End the table foot which will appear on every page.

end_table_header()[source]

End the table header 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.LongTable

A class that represents a long version of the tabularx environment.

This uses the ltablex package. This package modifies the tabularx environment so that it can be spread over multiple pages. This has the sideeffect that using this class in a document spreads all Tabularx elements 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_empty_row()[source]

Add an empty row to the table.

add_hline(start=None, end=None, *, color=None, cmidruleoption=None)[source]

Add a horizontal line to the table.

Parameters:
  • start (int) – At what cell the line should begin
  • end (int) – At what cell the line should end
  • color (str) – The hline color.
  • cmidruleoption (str) – The option to be used for the booktabs cmidrule, i.e. the x in \cmidrule(x){1-3}.
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 list or tuple) – 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.

End the table foot which will appear on every page.

end_table_header()[source]

End the table header 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.UnsafeCommand

A class representing a new column type.

It uses the \newcolumntype command, 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 None this is calculated automatically.