mlresearch.latex.export_longtable

mlresearch.latex.export_longtable(table, path=None, caption=None, label=None, index=True)[source]

Exports a pandas dataframe to LaTeX (longtable) format.

This function replaces df.to_latex when there are latex commands in the table. Requires \usepackage{booktabs} and \usepackage{longtable} in the LaTeX preamble.

Warning

Do not pass a table with column names, index names or values containing an underscore (“_”), as it will result in an error in LaTeX. If you wish to have underscores in the LaTeX table, add a backslash before the underscore.

Parameters:
tablepd.DataFrame

Dataframe with results statistics. Must not contain non-indexed metadata. Supports both single and multi index.

pathstr, default=None

File path to write to. If None, the output is returned as a string.

captionstr or tuple, default=None

Tuple (full_caption, short_caption), which results in \caption[short_caption]{full_caption}; if a single string is passed, no short caption will be set.

labelstr, default=None

The LaTeX label to be placed inside \label{} in the output. This is used with \ref{} in the main .tex file.

indexbool, default=True

Write row names (index).

Returns:
tex_tablestr or None

If path is None, returns the result as a string. Otherwise returns None.