Basic Interface

Creating tables and adding rows

[1]:
from tabletexifier import Table

tab = Table(header = ["foo", "bar", "zeta"])
tab.add_row([1,2, "string_value"])
print(tab)
-----------------------------
-----------------------------
  foo    bar        zeta
-----------------------------
   1      2     string_value
-----------------------------
[2]:
print(tab.build_latex())

\begin{table}[H]
\caption{}
\label{}
\centering
\begin{tabular}{ccc}\hline \hline
 foo  & bar  &     zeta     \\ \hline
  1   &  2   & string_value \\ \hline
\end{tabular}
\end{table}

We can control the number of decimal places through:

[3]:
tab.set_decimal_places(2)
print(tab)
print(tab.build_latex())
-----------------------------
-----------------------------
  foo    bar        zeta
-----------------------------
  1.00   2.00   string_value
-----------------------------

\begin{table}[H]
\caption{}
\label{}
\centering
\begin{tabular}{ccc}\hline \hline
 foo  & bar  &     zeta     \\ \hline
  1   &  2   & string_value \\ \hline
\end{tabular}
\end{table}

The columns also allow the data to be tuples or lists. However, the decimal places do not apply to them:

[4]:
tab.add_row(['third',[1,1,1], []])
tab.set_decimal_places(2)
print(tab)
-------------------------------------
-------------------------------------
   foo        bar           zeta
-------------------------------------
   1.00       2.00      string_value
  third    [1, 1, 1]         []
-------------------------------------

Configure the horizontal and vertical lines

We can configure the pattern of lines on the two versions (text and LaTeX):

[5]:
for style in tab.style_map:
    print(f"Starting with : {style}\n\n")
    tab.update_table_style(style)
    print(tab)
    print("\n\n")
Starting with : T


   foo   |    bar           zeta
---------+---------------------------
   1.00  |    2.00      string_value
  third  | [1, 1, 1]         []



Starting with : A


+--------+------------+--------------+
|  foo   |    bar     |     zeta     |
+--------+------------+--------------+
|  1.00  |    2.00    | string_value |
+--------+------------+--------------+
| third  | [1, 1, 1]  |      []      |
+--------+------------+--------------+



Starting with : MNRAS


-------------------------------------
   foo        bar           zeta
-------------------------------------
   1.00       2.00      string_value
  third    [1, 1, 1]         []



Starting with : NoLines


   foo        bar           zeta
   1.00       2.00      string_value
  third    [1, 1, 1]         []



Starting with : A&A


-------------------------------------
-------------------------------------
   foo        bar           zeta
-------------------------------------
   1.00       2.00      string_value
  third    [1, 1, 1]         []
-------------------------------------



We can also manually add vertical and horizontal lines:

[6]:
t = Table(header=[1, 2, 3, 4], table_style="NoLines")
t.add_row(list(range(5, 9)))
t.add_row(list(range(9, 13)))

t.add_vline(loc=1)
t.add_hline(loc=1)
print(t)
print(t.build_latex())
  1  | 2    3    4
-----+--------------
  5  | 6    7    8
  9  | 10   11   12

\begin{table}[H]
\caption{}
\label{}
\centering
\begin{tabular}{c|ccc}
 1  & 2  & 3  & 4  \\ \hline
 5  & 6  & 7  & 8  \\
 9  & 10 & 11 & 12 \\
\end{tabular}
\end{table}

Storing the tables to a file

The tables can also be stored to disk:

[7]:
tab.write_to_file("temp.txt", write_LaTeX=True, write_table=True)