python - 使用制表 Python 包生成适当的 LaTeX 表

标签 python latex

我正在使用 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 like latex but does not escape LaTeX commands and special characters.

关于python - 使用制表 Python 包生成适当的 LaTeX 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35418787/

相关文章:

python - 实时统计分析

python - 使用级别中的唯一值重新索引 MultiIndex

image - 图片没有 LaTeX 边距

latex - 在 LaTeX 中从 1 个 TEX 文件制作多个 PDF?

latex - 从Maxima输入生成LaTeX

python - 用于在 Python 中解析复杂制表符分隔/csv 文件的循环

python - 根据类 python 2.7 中的变量按字母顺序对类列表进行排序

python - 如何测试或模拟 "if __name__ == ' __main_ _'"内容

ant - 在 Jenkins/Hudson 上构建 LaTeX PDF

r - 如何在ggplot2中产生没有 curl 的λ?