3

I would like to include a code block in a presentation I am preparing with Restructured Text. But the font used in the code block is huge and it can not fit inside resulting code box:

enter image description here

How can I reduce the font size used in code blocks?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86

3 Answers3

1

Set the fontSize property of the code style in your style file.

e.g.

code:
    parent: literal
    fontSize: 10
Rob Allen
  • 12,643
  • 1
  • 40
  • 49
1

Some of the builtin themes (alabaster) accept usage of custom.css.

Create _static/custom.css and add the following to adjust the code-block font-size:

_static/custom.css:

.highlight { background: #f8f8f8; font-size: x-small;}
monkut
  • 42,176
  • 24
  • 124
  • 155
  • The names have changed a bit: `div.highlight {background-color: {{ theme_code_highlight_bg }}; font-size: x-small;}`, see https://github.com/bitprophet/alabaster/blob/master/alabaster/static/alabaster.css_t – sfinkens Jan 05 '22 at 15:25
0

You need a layout.html in a dir mysources/_templates and in your mysources/conf.py you need a declaration templates_path = ['_templates'].

In layout.html add a declaration

div.highlight {
    font-size  : 0.8em; /* or another value you prefer */
}

This works for me because I use the html_theme sphinxdoc. Maybe in other themes the declarations differ. If so you must find out the declaration by a html debugger like Inspektor in Firefox or Developer Tools in Chrome or DOM Explorer in IE.

Humbalan
  • 677
  • 3
  • 14
  • Sorry, I just did not see that you use rst2pdf. My tool is Sphinx. Hope, that my answer gives you a hint anyhow. – Humbalan Jul 27 '16 at 14:29