10

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

在某些 .rst 中,我有特殊宽度的表格,例如:

.. 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. 

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

4

5 回答 5

13

实际上是命令

.. tabularcolumns:: |p{4.5cm}|p{8.5cm}| 

在.. list-table:: 之前需要

https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-tabularcolumns

于 2010-05-26T19:09:27.787 回答
1

尝试:

:widths: 50, 50

用逗号分隔符。

输出还取决于您的表是如何用 rst 编写的。

我假设您使用的是标准的 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|}
于 2010-04-07T20:50:22.293 回答
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 问题。

文档谈论的“自动”宽度对我来说也不是很实用,链接往往会溢出。

于 2012-03-29T20:47:16.973 回答
0

由于我有大量文档,因此我尝试修复乳胶生成。另外,我认为 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,请记住将整数之一转换为浮点数或从 __ 未来 __ 导入除法。

于 2013-11-12T12:11:35.383 回答
0

docutils rst2latex writer 对表格有一些问题:http://docutils.sourceforge.net/docs/dev/todo.html#tables,所以也许您的问题与此有关?我认为 Sphinx 编写器是基于 rst2latex 的,因此可能存在相同的问题。

于 2010-04-10T08:49:41.453 回答