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.
Given the following example:
Output:
Tabulate adds the escape character
\to every instance of an underscore_but ignores the thereby increasing width of the column.