python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

Additional width for escaping characters is not considered in `"latex"` tablefmt

Open sueskind opened this issue 2 years ago • 0 comments

Given the following example:

data = {"col1": ["first", "a_long_second_row", "third_row"], "col2": [1, 2, 3]}
df = pd.DataFrame(data)

print(tabulate(data, tablefmt="latex"))

Output:

\begin{tabular}{lr}
\hline
 first             & 1 \\
 a\_long\_second\_row & 2 \\
 third\_row         & 3 \\
\hline
\end{tabular}

Tabulate adds the escape character \ to every instance of an underscore _ but ignores the thereby increasing width of the column.

sueskind avatar Jan 31 '23 15:01 sueskind