如何防止pandas.Dataframe.to_latex在乳胶公式字符(即美元符号/括号)之前添加转义\字符? [英] How to prevent pandas.Dataframe.to_latex from adding escape \ characters before latex formula characters (i.e dollar signs/brackets)?

查看:80
本文介绍了如何防止pandas.Dataframe.to_latex在乳胶公式字符(即美元符号/括号)之前添加转义\字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为纸张生成一个数据表,我可以使用熊猫将其插入LaTeX文档.但是,表头和元素的条目都必须是乳胶( $ ... $ )中的数学公式.在我的情况下,这是因为其中一些是因为它们带有下标,而另一些是因为所有表值都需要具有上下误差线,例如 0.21 ^ {+ 0.03} _ {-0.05} 等...

I'm trying to produce a data table for a paper that I can insert into the LaTeX document, using pandas. However, the entries of both the table headers and the elements need to be mathematical formulas in latex ($...$). In my case, this is because some of them because they have subscripts, and others because all the table values need to have upper and lower error bars, i.e like 0.21^{+0.03}_{-0.05} etc...

因此,我制作了一个带有字符串元素的熊猫表,例如'$ 0.21 ^ {+ 0.03} _ {-0.05} $'.美元符号之所以存在,是因为据我所知LaTeX需要将此解释为公式.不幸的是,当我然后尝试使用 df.to_latex(...)将表写入乳胶格式时,解析器将转义字符 \ 放在每个美元符号的前面.下划线,方括号和所有乳胶公式字符('$ 0.21 ^ {+ 0.03} _ {-0.05} $'变为'\ $ 0.21 \ ^ \ {+0.03 \} \ _ \ {-0.05 \} $'

So I made a pandas table with string elements such as '$0.21^{+0.03}_{-0.05}$'. The dollar signs are there because LaTeX needs to interpret this as a formula as far as I can tell. Unfortunately, when I then try to write the table into latex format with df.to_latex(...), the parser puts escape characters \ in front of every dollar sign. The same seems to happen with the underscores, brackets, and all the latex formula characters ('$0.21^{+0.03}_{-0.05}$' becomes '\$0.21\^\{+0.03\}\_\{-0.05\}$'

我将如何阻止这种情况的发生?

How would I be able to block this from happening?

推荐答案

基于 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆