我正在使用 tabulate用于生成正确的 LaTeX 格式表格的 Python 包。
这是一个 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")
我从这个例子中得到的是:
\begin{tabular}{l}
\hline
\$2.4\textbackslash{}pm0.5\$ \\
\$45.1\textbackslash{}pm8.0\$ \\
\hline
\end{tabular}
正确的格式应该是:
\begin{tabular}{l}
\hline
$2.4\pm0.5$ \\
$45.1\pm8.0$ \\
\hline
\end{tabular}
即:程序包在 $
符号之前插入反斜杠,并将 \pm
中的反斜杠替换为 \textbackslash{}
。
能否生成格式正确的表格?
最佳答案
更改 tablefmt
使其等于 latex_raw
。来自文档:
latex_raw
behaves likelatex
but does not escape LaTeX commands and special characters.
关于python - 使用制表 Python 包生成适当的 LaTeX 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35418787/