我正在尝试用Python实现PyLaTeX来创建一个LaTex表。表格中的两个单元格我希望它们是希腊字母,如图所示。看看我的代码块,看到我输入了'\gamma'
和'\gamma_{sat}'
,但它不起作用,只是以文本形式打印出来,有人知道我如何解决这个问题吗?
我尝试过输入'\\gamma'
、r'\gamma'
、'$\gamma'
……但我就是不知道该怎么做。
# Creo una subsección para las tablas.
with doc.create(Subsection('Tablas de interés', numbering = False)):
# Creo el entorno Table.
with doc.create(Table(position='h!')) as entorno_table:
# Creo el entorno Center.
with entorno_table.create(Center()) as centered:
# Creo el entorno Tabular.
with centered.create(Tabular('|c|c|c|c|c|')) as entorno_tabular:
# Construyo la tabla.
entorno_tabular.add_hline()
entorno_tabular.add_row(('Estrato', 'Profundidad Inicial', 'Profundidad final', '\gamma', '\gamma_{sat}'))
entorno_tabular.add_hline()
entorno_tabular.add_row(('1', '0', '1', '14.6', '18.38'))
entorno_tabular.add_hline()
entorno_tabular.add_row(('2', '1', '2.5', '14.9', '18.48'))
entorno_tabular.add_hline()
entorno_tabular.add_row(('3', '2.5', '5', '15.2', '18.58'))
entorno_tabular.add_hline()
entorno_tabular.add_row(('4', '5', '6.7', '15.5', '18.68'))
entorno_tabular.add_hline()
entorno_tabular.add_row(('5', '6.7', '10', '15.8', '18.78'))
entorno_tabular.add_hline()
#table.add_empty_row()
# Añado el caption al entorno Table.
entorno_table.add_caption('Propiedades del suelo para pregunta ##.')
[1]: https://i.stack.imgur.com/CPC6d.png
发布于 2021-04-30 23:32:37
使用NoEscape
将Latex命令放入文档中。您还需要将gammas设置为数学模式$.. $
。
from pylatex import Document, Subsection, Table, Tabular, Center, NoEscape # ...
# ...
entorno_tabular.add_row(('Estrato', 'Profundidad Inicial', 'Profundidad final', NoEscape('$\gamma$'), NoEscape('$\gamma_{sat}$')))
# ...
https://stackoverflow.com/questions/67336272
复制相似问题