I'm using the tabulate Python package to generate a properly LaTeX formatted table.
Here's a MWE:
from tabulate import tabulate
table = [[r"${:.1f}\pm{:.1f}$".format(2.3564, 0.5487)],
[r"${:.1f}\pm{:.1f}$".format(45.1236, 8.00021)]
]
print tabulate(table, tablefmt="latex")
What I get with this example is:
\begin{tabular}{l}
\hline
\$2.4\textbackslash{}pm0.5\$ \\
\$45.1\textbackslash{}pm8.0\$ \\
\hline
\end{tabular}
when the proper formatting would be:
\begin{tabular}{l}
\hline
$2.4\pm0.5$ \\
$45.1\pm8.0$ \\
\hline
\end{tabular}
I.e.: the package is inserting backlashes before the $ symbols, and replacing the backlash in \pm with \textbackslash{}.
Is it possible to generate the correct formatted table?
解决方案
Change the tablefmt so that it is equal to latex_raw. From the documentation:
latex_raw behaves like latex but does not escape LaTeX commands
and special characters.