强制 Sphinx 使用 longtable 指令,以在长表中正确添加分页符

Gre*_*ard 3 latex python-sphinx

我正在开发一个项目,我们可以生成 HTML 和 PDF 文档。

当表超过 30 行时,sp​​hinx 正确使用 Latex longtable 包。但是,对于较小的表,它使用 tabulary 包。

我的问题是我有一些表少于 30 行,但由于行很大,我需要分页符。

从我所有的阅读(具体来说,这里: https: //github.com/sphinx-doc/sphinx/issues/1898)看来,我应该简单地通过指定“:class:longtable”来强制sphinx使用longtable

不幸的是,我没有成功添加此规范,因为我的表没有使用单独的指令指定。

这是我的表的定义方式:

.. tabularcolumns:: |p{1cm}|p{4cm}|p{10cm}|

+--------+-----------------+--------------------------+
| Step # | Process Step(s) | Detail                   |
+========+=================+==========================+
| 1      | Testing         | Testing  Testing Testing |
+--------+-----------------+--------------------------+
Run Code Online (Sandbox Code Playgroud)

我得到的所有在线示例都使用 list-tables 或 csv-tables,然后添加 longtable 命令作为相关指令的一部分。例如:

.. tabularcolumns:: |p{1cm}|p{7cm}|

.. csv-table:: Lorem Ipsum
   :file: _files/lorem-tab.csv
   :header-rows: 1
   :class: longtable
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个,但不幸的是它不起作用:

.. tabularcolumns:: |p{1cm}|p{4cm}|p{10cm}|
   :class: longtable

+--------+-----------------+--------------------------+
| Step # | Process Step(s) | Detail                   |
+========+=================+==========================+
| 1      | Testing         | Testing  Testing Testing |
+--------+-----------------+--------------------------+
Run Code Online (Sandbox Code Playgroud)

尝试制作 pdf 时出现以下异常:

! Package array Error:  Illegal pream-token (:): `c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.663 :class: longtable}
Run Code Online (Sandbox Code Playgroud)

Gre*_*ard 6

在与同事进行一些橡皮鸭调试后,我们确定我需要添加 ..table 指令。然后,这会包装我的简单表格,并为 :class: 定义提供一个位置。

所以我的表现在定义如下:

.. tabularcolumns:: |p{1cm}|p{4cm}|p{10cm}|

.. table:: My Table
   :widths: auto
   :class: longtable

   +--------+-----------------+--------------------------+
   | Step # | Process Step(s) | Detail                   |
   +========+=================+==========================+
   | 1      | Testing         | Testing  Testing Testing |
   +--------+-----------------+--------------------------+
Run Code Online (Sandbox Code Playgroud)

这对我们的问题进行了排序,并且它仍然从 tabularcolumns 指令中读取列规范。