Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I thought to cross reference I have to enter the starting format as

:ref:`Link Text <CrossReferenceLabel>`

Then use it later on by writing

.. _CrossReferenceLabel:

Like the following.

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


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

The link is created for the Link Text, however the destination doesn't seem to have the cross reference.

like image 558
Iancovici Avatar asked Nov 01 '25 20:11

Iancovici


1 Answers

You are so close. I would place the label above the Dog table because that is what it labels.

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

.. _DogLabel:

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

The third column is not necessary in this example, so you could remove it.

Also grid style tables are the most difficult syntax to edit out of the four different table styles. See Tables documentation for alternatives.

Additionally if you want to reference something within a table cell, you must follow reStructuredText rules about whitespace after a label. For example.

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

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

To me it makes more sense to label the table than a cell in the table.

like image 69
Steve Piercy Avatar answered Nov 03 '25 19:11

Steve Piercy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!