将表中的表转换为LaTeX

时间:2010-04-07 18:37:06

标签: latex python-sphinx

我有一些.rst文件,我使用标准的sphinx转换器将它们转换为.tex文件。

在某些情况下,我有一些特殊宽度的表格,如:

.. list-table::  
   :widths: 50 50 

生成的.tex始终包含以下表格:

\begin{tabulary}{\textwidth}{|L|L|}

因此,列宽会丢失。

如何在将rst转换为乳胶时保留色谱柱宽度?


我也使用了逗号分隔符,

.. list-table::  
   :widths: 50 , 50 
   :header-rows: 1 

* - SETTING 
  - DESCRIPTION
* - Enable 
  - Enables or disables internal tracing.
* - Verbose 
  - Enables or disables extended internal tracing. 

但它不起作用..也许我使用了一个坏的转换器?你推荐什么转换器?

5 个答案:

答案 0 :(得分:13)

实际上是命令

.. tabularcolumns:: |p{4.5cm}|p{8.5cm}| 
在... list-table ::

之前需要

http://sphinx.pocoo.org/markup/misc.html?highlight=tabularcolumns#dir-tabularcolumns

答案 1 :(得分:1)

尝试:

:widths: 50, 50

使用逗号分隔符。

输出还取决于第一次写入表的方式。

我假设您使用的是标准的rst表语法,而不是使用项目符号列表创建表格(尽可能)。如需更多帮助,请尝试http://docutils.sourceforge.net/docs/ref/rst/directives.html#tables

此外,如果50, 50是列宽,则乳胶代码应如下所示:

\begin{tabulary}{  1\textwidth}{ | p{0.5} | p{0.5} | }

\begin{tabulary}{total width of table}{| column width| column width|}

答案 2 :(得分:0)

docutils rst2latex编写器对表有一些问题:http://docutils.sourceforge.net/docs/dev/todo.html#tables,所以也许你的问题与此有关?我认为Sphinx作家基于rst2latex,因此可能会遇到同样的问题。

答案 3 :(得分:0)

我可以证实这一点:

.. list-table::
:widths: 10 40 50

* - Module
  - Link
  - Description 

适用于rst2latex

\setlength{\DUtablewidth}{\linewidth}
\begin{longtable*}[c]{|p{0.104\DUtablewidth}|p{0.375\DUtablewidth}|p{0.465\DUtablewidth}|}
\hline

Module
 & 
Link
 & 
Description
 \\
\hline

但是使用狮身人面像,我会得到OP所提供的内容。所以我不会收集rst2latex问题。

文档所说的“自动”宽度对我来说也不是很有用,链接往往会流血。

答案 4 :(得分:0)

由于我有大量文档,我试图修复胶乳生成。另外,我认为第一个文件中的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,记住要么将其中一个整数转换为浮点数,要么从__ future __中导入除法。

相关问题