You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Sphinx的ReadTheDocs主题中缩小指定表格的字体大小?

解决Sphinx+ReadTheDocs主题单个表格缩小字体的问题

针对你遇到的list-table不支持:font-size:选项、主题容器覆盖自定义样式的问题,给你两种精准修改单个表格字体的方法:

方法1:给目标表格添加自定义CSS类

  1. 在Sphinx项目里创建_static目录(如果没有的话),然后在里面新建custom.css文件。
  2. 打开项目根目录的conf.py,添加一行配置引入这个自定义CSS:
    html_css_files = ['custom.css']
    
  3. 编辑custom.css,写入专门针对小字体表格的样式:
    /* 只给带small-table类的响应式表格缩小字体 */
    .wy-table-responsive.small-table table {
        font-size: 10px;
        /* 可选:如果觉得行间距太宽,可以加line-height: 1.2;调整 */
    }
    
  4. 修改你的list-table代码,加上:class:选项指定自定义类:
    .. list-table:: Issues & To Do's
       :class: small-table
       :widths: 15 10 15 25 20 15
       :header-rows: 1
    
       * - Date
         - Issue or To Do
         - Title
         - Description
         - Action
         - Closed
       * - 03/02/2025
         - Issue
         - Hyperlinks
         - document.xml.rels
         - check with Beeblebrox
         - infinity date
    

方法2:用容器包裹目标表格

如果不想直接给表格加类,也可以用容器把整个表格包起来:

  1. 同样先按方法1的步骤配置好custom.css,然后添加下面的样式:
    /* 给容器内的响应式表格缩小字体 */
    .small-table-container .wy-table-responsive table {
        font-size: 10px;
    }
    
  2. 在rst文件里用container指令包裹你的list-table:
    .. container:: small-table-container
    
       .. list-table:: Issues & To Do's
          :widths: 15 10 15 25 20 15
          :header-rows: 1
    
          * - Date
            - Issue or To Do
            - Title
            - Description
            - Action
            - Closed
          * - 03/02/2025
            - Issue
            - Hyperlinks
            - document.xml.rels
            - check with Beeblebrox
            - infinity date
    

这两种方法都是通过CSS组合选择器,精准定位到你要修改的表格,不会影响其他表格的样式,完美避开ReadTheDocs主题的容器样式覆盖问题。

内容的提问来源于stack exchange,提问作者PeetsB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 14:55:11