I'd like to reduce the font size used for code blocks included in my Org-Mode/Beamer presenation. What command(s) can I use so as only affect the content of the src block?

Here's a minimal working example: the code block is near the end:

#+TITLE:     <<title>>
#+AUTHOR:    Dave
#+DATE:      <<date>>
#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc toc:nil \n:nil
#+INFOJS_OPT: view:nil toc:t ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js

#+startup: beamer
#+LATEX_CLASS: beamer
#+LATEX_HEADER: \usepackage{pgfpages}
#+LATEX_HEADER: \pgfpagesuselayout{resize to}[letterpaper,border shrink=5mm,landscape]
#+LATEX_HEADER: \usetheme{Dresden}
#+LATEX_HEADER: \usepackage[utf8x]{inputenc}
#+LATEX_HEADER: \setbeamertemplate{itemize items}[default]
#+LATEX_HEADER: \setbeamertemplate{enumerate items}[default]
#+LATEX_HEADER: \institute{} 

#+COLUMNS: %40ITEM %10BEAMER_env(Env) %9BEAMER_envargs(Env Args) %4BEAMER_col(Col) %10BEAMER_extra(Extra)

* Presentation

** Code Example
*** Text
:BEAMER_env: ignoreheading 

- Text describing code
- More text

*** Graphics
:BEAMER_env: ignoreheading 

% I want the text in this code block to be smaller
#+begin_src python
import sys
import os
import super_cool_module


It depends on whether you load the listings package in your .emacs file. You can check the contents of the Emacs variable org-latex-default-packages-alist (use the key combo C-h v to see the help and contents of a variable).

If the listings package is not loaded, org-mode will use the verbatim LaTeX environment to typeset the code. In that case you can use the fancyvrb LaTeX package to typeset the code in a smaller font. For example, add the following to your org-mode file:

#+LATEX_HEADER: \RequirePackage{fancyvrb}
#+LATEX_HEADER: \DefineVerbatimEnvironment{verbatim}{Verbatim}{fontsize=\scriptsize}

This redefines the default verbatim environment.

If the listings package is loaded, you can add the following LaTeX code to your org file to get a smaller font for the code:

#+LaTeX_HEADER: \lstset{basicstyle=\scriptsize\ttfamily}

This will set the style to use a monospaced font of size \scriptsize.

\tiny is the smallest relative font size in LaTeX. In order of increasing size you could try: \scriptsize, \footnotesize, \small, which are all smaller than \normalsize.

| improve this answer | |
  • How could I get latex inline $F=ma$ to be a smaller font size -- for HTML or Latex export? – 147pm Jun 24 '16 at 18:37
  • Question: what is the difference between RequirePackage and usepackage? (I have a bunch of usepackage in my current file) – Dave Sep 29 '17 at 19:35
  • @Dave: there is not much difference. Officially, usepackage is used in a normal LaTeX document and RequirePackage is used within LaTeX packages (.sty files). – ph0t0nix Dec 4 '17 at 10:59

Assuming you use the listing package, which means you have in your org mode file preamble

#+LATEX_HEADER: \usepackage{listings}

you can set any specific option available in the \lstset{} command. To set a latex scriptsize font for a specific snippet, you can override the default lstset options like this:

#+ATTR_LATEX: :options basicstyle=\ttfamily\scriptsize
#+begin_src C
   some code
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.