【问题标题】:How to define the the height of the csv table in reStructuredText?如何在 reStructuredText 中定义 csv 表的高度?
【发布时间】:2018-02-08 15:29:36
【问题描述】:

我正在使用此代码从 csv 为我在 readthedocs 中的文档创建一个表:

.. csv-table:: Markram et al. Model & Network configuration file
   :file: ../config_files/Markram_config_file.csv
   :header-rows: 1

CSV 很大,有很多行和列。对于列,一切都很好,因为它只适合页面中的几列,而其他列可以通过在表格中向右滚动来访问。 但是,所有行都放在页面中,我无法为csv table 指定特定的“长度”或“高度”。 我试图通过:height: 100px 指定高度,但它没有为表格定义。无论如何要指定吗? Here's 我在表格中使用的示例。

【问题讨论】:

    标签: restructuredtext


    【解决方案1】:

    在您的 .. csv-table 指令之前,将其放在上面并用空行分隔(请参阅 https://stackoverflow.com/a/46195021/2214933):

    .. rst-class:: table-myclass
    
    .. csv-table:: blah blah blah
    

    上面会为渲染的 HTML 表格应用一个类名。

    然后在您的 Sphinx 主题中,添加自定义样式。假设您想限制每个表格行的高度(不是表格本身,因为 100px 对于很多数据来说非常短),请输入以下内容:

    table.myclass tbody tr {height: 100px;}
    

    调整 CSS 选择器和样式以适应口味。

    how to create custom styles in Sphinx

    【讨论】:

    • 我在./_static/css/custom.css 中创建了一个文件,并将table.myclass tbody tr {height: 100px;} 添加到文件中。然后我根据this 链接将def setup(app): app.add_stylesheet('css/custom.css') 添加到我的conf.py 中,但我的表格仍然很长。提醒您一下,我希望它简短但可滚动。
    【解决方案2】:

    我添加了一个文件_static/css/custom.css,其内容如下(灵感来自https://stackoverflow.com/a/4457290/3362993):

    table.docutils {
        display: block;
        height: <your_height>px;
        overflow-y: scroll;
        width: <your_width>%
      }
    

    并将以下行添加到conf.py

    html_css_files = [
        "css/custom.css",
    ]
    

    我发现要识别 css 文件需要尾随列表逗号:耸耸肩:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      相关资源
      最近更新 更多