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?
The tabular environment is the default LaTeX method to create tables. You must specify a parameter to this environment; here we use {c c c} which tells LaTeX that there are three columns and the text inside each one of them must be centred.
Click the Python Interpreter tab within your project tab. Click the small + symbol to add a new library to the project. Now type in the library to be installed, in your example "tabulate" without quotes, and click Install Package . Wait for the installation to terminate and close all pop-ups.
Change the tablefmt
so that it is equal to latex_raw
. From the documentation:
latex_raw
behaves likelatex
but does not escape LaTeX commands and special characters.
This
tabulate.LATEX_ESCAPE_RULES = {}
worked for me
>>> tabulate.LATEX_ESCAPE_RULES = {}
>>> print(tabulate.tabulate([[r'\alpha']], tablefmt='latex'))
\begin{tabular}{l}
\hline
\alpha \\
\hline
\end{tabular}
worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With