Jeremy Jarrell
Jeremy Jarrell

Reputation: 679

Include links in Sphinx table without extra whitespace

I'm trying to create a table of links using the simple table format in Sphinx, like the example below:

===================================  ======
Website                              Type                                           
===================================  ======
`Google <https://www.google.com>`__  Search
`Yahoo <https://www.yahoo.com>`__    Search
`CNN <https://www.cnn.com>`__        News  
===================================  ======

If I understand correctly, I have to stretch the header breaks to the width of the longest row in the table, including the links. However, when the table is rendered the website is rendered as a link, leading to a lot of empty whitespace in the Website column.

enter image description here

Is there a way to create a table where the column is only as wide as the longest rendered hyperlink?

Upvotes: 2

Views: 943

Answers (1)

mzjn
mzjn

Reputation: 50947

Wrapping the table in a table directive with :widths: auto works for me (tested with Sphinx 4.2.0).

.. table::
   :align: left
   :widths: auto
   
   ================================== ======
   Website                            Type                                           
   ================================== ======
   `Google <https://www.google.com>`_ Search
   `Yahoo <https://www.yahoo.com>`_   Search
   `CNN <https://www.cnn.com>`_       News  
   ================================== ======

Upvotes: 2

Related Questions