astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.16k stars 165 forks source link

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

Open sueskind opened 1 year ago

sueskind commented 1 year ago

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.