如何在Sphinx的ReadTheDocs主题中缩小指定表格的字体大小?
解决Sphinx+ReadTheDocs主题单个表格缩小字体的问题
针对你遇到的list-table不支持:font-size:选项、主题容器覆盖自定义样式的问题,给你两种精准修改单个表格字体的方法:
方法1:给目标表格添加自定义CSS类
- 在Sphinx项目里创建
_static目录(如果没有的话),然后在里面新建custom.css文件。 - 打开项目根目录的
conf.py,添加一行配置引入这个自定义CSS:html_css_files = ['custom.css'] - 编辑
custom.css,写入专门针对小字体表格的样式:/* 只给带small-table类的响应式表格缩小字体 */ .wy-table-responsive.small-table table { font-size: 10px; /* 可选:如果觉得行间距太宽,可以加line-height: 1.2;调整 */ } - 修改你的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的步骤配置好
custom.css,然后添加下面的样式:/* 给容器内的响应式表格缩小字体 */ .small-table-container .wy-table-responsive table { font-size: 10px; } - 在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
相关产品推荐
相关产品推荐

