由于我有大量文档,因此我尝试修复乳胶生成。另外,我认为 rst 文件中的 Latex 表示法是一个缺点,因为它不一致并且需要编辑部分学习敏感的标记语言。
我用我自己的版本替换了 LaTeXTranslator.depart_table。我复制了原始的depart_table 并添加了以下代码(缩短):
def my_depart_table (self, node):
totalColwidth = 0
givenColwidth = []
hasColwidth = False
for tgroup in node:
for tableColspec in tgroup:
try:
if tableColspec.has_key('colwidth'):
totalColwidth += tableColspec['colwidth']
givenColwidth.append(tableColspec['colwidth'])
hasColwidth = True
except:
print "colspec missing. \n"
# original code
if hasColwidth:
colspec = ""
for thisColwidth in givenColwidth:
colspec += ('>{\RaggedRight}p{%.3f\\linewidth}' % (0.95 * thisColwidth / totalColwidth))
#print "using widths: %.3f %s %s" % ((0.95 * thisColwidth / totalColwidth), thisColwidth, totalColwidth)
self.body.append('{' + colspec + '}\n')
# more original code
LaTeXTranslator.depart_table = my_depart_table
我既不精通 Python 也不精通 Sphinx,因此使用风险自负。我希望你能得到这个想法,甚至可以提供建议。
如果您使用 Python < 3.0 并希望完全删除因子 0.95,请记住将整数之一转换为浮点数或从 __ 未来 __ 导入除法。