Multicolumns and multirows
[21]:
from tabletexifier import Table
t = Table(header=[1, 2, 3, 4], table_style="A")
t.add_row(list(range(5, 9)))
t.add_row(list(range(9, 13)))
print(t)
+----+----+----+----+
| 1 | 2 | 3 | 4 |
+----+----+----+----+
| 5 | 6 | 7 | 8 |
+----+----+----+----+
| 9 | 10 | 11 | 12 |
+----+----+----+----+
Setting as a multicolumn, works on both the terminal version of the table and, the changes are propagated to LaTeX through the multicol and multirow commands
[22]:
t.set_cell_as_multi_col(start_col=0,
start_row=1,
number_of_cols=1
)
t.set_cell_as_multi_row(start_row=1,
start_col= 2,
number_of_rows=1)
print(t)
print(t.build_latex())
+----+----+----+----+
| 1 | 2 | 3 | 4 |
+----+----+----+----+
| 5 | 7 | 8 |
+----+----+ +----+
| 9 | 10 | | 12 |
+----+----+----+----+
\begin{table}[H]
\caption{}
\label{}
\centering
\begin{tabular}{c|c|c|c|}
1 & 2 & 3 & 4 \\ \hline
\multicolumn{2}{c}{5} &\multirow{2}{*}{7}& 8 \\ \hline
9 & 10 & & 12 \\ \hline
\end{tabular}
\end{table}
There are a few caveats if we attempt to build a multicol and a multirow (i.e. build a square of cells):
On the text-version we get the extra “+” if the vlines are active in those cells
On the LaTex version, the hlines are broken (it keeps using the :nbsphinx-math:`hlines `instead of the clines)
[28]:
t = Table(header=[1, 2, 3, 4], table_style="A")
t.add_row(list(range(5, 9)))
t.add_row(list(range(9, 13)))
t.set_cell_as_multi_col(start_col=0,
start_row=1,
number_of_cols=1
)
t.set_cell_as_multi_col(start_col=0,
start_row=2,
number_of_cols=1
)
t.set_cell_as_multi_row(start_row=1,
start_col= 0,
number_of_rows=1)
t.set_cell_as_multi_row(start_row=1,
start_col= 1,
number_of_rows=1)
print(t)
print(t.build_latex())
+----+----+----+----+
| 1 | 2 | 3 | 4 |
+----+----+----+----+
| 5 | 7 | 8 |
+ + +----+----+
| | 11 | 12 |
+----+----+----+----+
\begin{table}[H]
\caption{}
\label{}
\centering
\begin{tabular}{c|c|c|c|}
1 & 2 & 3 & 4 \\ \hline
\multicolumn{2}{c}{\multirow{2}{*}{5}} & 7 & 8 \\ \hline
\multicolumn{2}{c}{} & 11 & 12 \\ \hline
\end{tabular}
\end{table}