eelbrain.fmtxt.Table

class eelbrain.fmtxt.Table(columns, rules=True, title=None, caption=None, rows=())

A table

Parameters:
  • columns (str) – alignment for each column, e.g. 'lrr'.

  • rules (bool) – Add toprule and bottomrule.

  • title (FMTextLike) – Title for the table.

  • caption (FMTextLike) – Caption for the table.

  • rows (Sequence[Row]) – Table body.

Examples

>>> from eelbrain import fmtxt
>>> table = fmtxt.Table('lll')
>>> table.cell()
>>> table.cell("example 1")
>>> table.cell("example 2")
>>> table.midrule()
>>> table.cell("string")
>>> table.cell('???')
>>> table.cell('another string')
>>> table.cell("Number")
>>> table.cell(4.5)
>>> table.cell(2./3, fmt='%.4g')
>>> print(table)
         example 1   example 2
-----------------------------------
string   ???         another string
Number   4.5         0.6667
>>> print(table.get_tex())
\begin{center}
\begin{tabular}{lll}
\toprule
 & example 1 & example 2 \\
\midrule
string & ??? & another string \\
Number & 4.5 & 0.6667 \\
\bottomrule
\end{tabular}
\end{center}
>>> table.save_tex()

Methods

add_row([at])

Add a row without affecting the cursor

append(table)

Append another table (has to have same column specification)

caption(content)

Set the table caption

cell([content, tag, width, just])

Add a cell to the table

cells(*cells, **kwargs)

Add several simple cells with one command

copy_pdf()

Copy PDF to clipboard

copy_tex()

Copy TeX to clipboard

empty_row()

endline()

Finish the active row

from_columns(columns[, column_spec, rules, ...])

Generate a Table from a list of columns

get_html([env])

Complete HTML representation

get_rtf([env])

get_str([env, delim, linesep, max_width])

Convert Table to str

get_tex([env])

TeX representation

get_tsv([delimiter, fmt])

Render the table to tab-separated values (TSV) string

midrule([span])

Add a midrule

save_docx([path])

Save table as *.docx (requires python-docx)

save_html([path, embed_images, meta])

Save in HTML format

save_pdf([path])

Save in PDF format

save_rtf([path])

Save in Rich Text format

save_tex([path])

Save in TeX format

save_tsv([path, delimiter, fmt])

Save the table as tab-separated values file

save_txt([path, fmt, delim, linesep])

Save the table as text file

title(content)

Set the table title