How to set the font size for code blocks in pandoc markdown?

tmaric picture tmaric · Nov 18, 2014 · Viewed 9.6k times · Source

this small example:

An example code snippet:

~~~{.cpp}
class A 
{
    public:
        static void f1 () {}; 

        virtual void f2 () = override; 
};
~~~

can be used to generate a PDF output with:

pandoc -o block-code.pdf block-code.txt

resulting in

Font sizes of the code snippet and the text are equal.

The font sizes of both the code and the text that are equal. How can I change the font size of the code snippets for the pdf (LaTex) pandoc output?

Answer

Vlad picture Vlad · Nov 26, 2017

You can simply add \small before the beginning of the code snippet and \normalsize after (to return to normal).

You can also add other similar commands. For instance, if your document is doublespaced, you can add \singlespace before the code snippet and \doublespacing after.

For this to work you need to add in the yaml at the beginning of your document the following:

---
header-includes:
    - \usepackage{setspace}
---