【问题标题】:Include links in Sphinx table without extra whitespace在 Sphinx 表中包含链接而无需额外的空格
【发布时间】:2021-12-14 21:07:51
【问题描述】:

我正在尝试使用 Sphinx 中的简单表格格式创建链接表,如下例所示:

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

如果我理解正确,我必须将页眉分隔符拉伸到表格中最长行的宽度,包括链接。然而,当表格被渲染时,网站被渲染为一个链接,导致网站列中有很多空白。

有没有办法创建一个表,其中列的宽度仅与最长呈现的超链接一样宽?

【问题讨论】:

  • 您可以在表格中添加一个 CSS 类,然后使用它来以百分比定义表格列的相对宽度。我也想知道为什么你在一个就足够的情况下使用双下划线?

标签: python-sphinx restructuredtext


【解决方案1】:

:widths: auto 将表格包装在table 指令中对我有用(使用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  
   ================================== ======

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    相关资源
    最近更新 更多