在 Sphinx 中,如何创建对 table 特定行的引用?

In Sphinx, how to create a reference to a table specific row?

我想交叉引用我必须输入起始格式

:ref:`Link Text <CrossReferenceLabel>`

以后写

就可以使用了
.. _CrossReferenceLabel:

点赞如下

   +-----------+-----------------------------------+-------+
   | Number    | Animal                            |       |
   +===========+===================================+=======+
   | 1         | :ref:`Dog <DogLabel>`             |       |
   +-----------+-----------------------------------+-------+
   | 2         | Cat                               |       |
   +-----------+-----------------------------------+-------+


   +-----------+-----------------------------------+-------+
   | Dog       | Services                          |       |
   |           | .. _DogLabel:                     |       |
   +===========+===================================+=======+
   | 1         | Vet                               |       |
   +-----------+-----------------------------------+-------+
   | 2         | Toy Shop                          |       |
   +-----------+-----------------------------------+-------+

link 是为 Link 文本创建的,但是目标似乎没有交叉引用。

所以接近。我会将标签放在 Dog table 上方,因为它就是它的标签。

+-----------+-----------------------------------+-------+
| Number    | Animal                            |       |
+===========+===================================+=======+
| 1         | :ref:`Dog <DogLabel>`             |       |
+-----------+-----------------------------------+-------+
| 2         | Cat                               |       |
+-----------+-----------------------------------+-------+

.. _DogLabel:

+-----------+-----------------------------------+-------+
| Dog       | Services                          |       |
+===========+===================================+=======+
| 1         | Vet                               |       |
+-----------+-----------------------------------+-------+
| 2         | Toy Shop                          |       |
+-----------+-----------------------------------+-------+

第三列在这个例子中不是必需的,所以你可以删除它。

此外,网格样式 table 是四种不同 table 样式中最难编辑的语法。请参阅 Tables documentation 了解替代方案。

此外,如果您想在 table 单元格中引用某些内容,则必须遵循关于标签后空格的 reStructuredText 规则。例如。

+-----------+-----------------------------------+-------+
| Number    | Animal                            |       |
+===========+===================================+=======+
| 1         | :ref:`Dog <DogLabel>`             |       |
+-----------+-----------------------------------+-------+
| 2         | Cat                               |       |
+-----------+-----------------------------------+-------+

+-----------+-----------------------------------+-------+
| Dog       | .. _DogLabel:                     |       |
|           |                                   |       |
|           | Services                          |       |
+===========+===================================+=======+
| 1         | Vet                               |       |
+-----------+-----------------------------------+-------+
| 2         | Toy Shop                          |       |
+-----------+-----------------------------------+-------+

对我来说,标记 table 比标记 table 中的单元格更有意义。