在样式文件中设置
fontSize
样式的 code
属性。
例如
code:
parent: literal
fontSize: 10
一些内置主题 (alabaster) 接受使用
custom.css
。
创建
_static/custom.css
并添加以下内容来调整 code-block
字体大小:
_static/custom.css:
.highlight { background: #f8f8f8; font-size: x-small;}
您需要在目录
mysources/_templates
中放置一个layout.html,并且在您的 mysources/conf.py
中您需要一个声明 templates_path = ['_templates']
。
在layout.html中添加声明
div.highlight {
font-size : 0.8em; /* or another value you prefer */
}
这对我有用,因为我使用 html_theme sphinxdoc。也许在其他主题中声明有所不同。如果是这样,您必须通过 html 调试器(例如 Firefox 中的 Inspektor 或 Chrome 中的开发人员工具或 IE 中的 DOM Explorer)找出声明。
首先,在文档根目录中创建一个名为
style_code_font_size.yaml
的文件,其中包含以下内容:
styles:
code:
parent: literal
fontSize: 8
如果您使用的是 Sphinx,请将此新样式添加到
pdf_stylesheets
中的 conf.py
:
pdf_stylesheets = ["twocolumn", "sphinx"]
pdf_stylesheets = ["style_code_font_size", "twocolumn", "sphinx"]