14

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
#+EMAIL:     
#+DATE:      <<date>>
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE:  en
#+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
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 
#+XSLT:




#+startup: beamer
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [bigger]
#+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{} 

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


* Presentation

** Code Example
*** Text
:PROPERTIES:
:BEAMER_env: ignoreheading 
:BEAMER_col:0.5
:END:

- Text describing code
- More text

*** Graphics
:PROPERTIES:
:BEAMER_env: ignoreheading 
:BEAMER_col:0.5
:END:

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

value=super_cool_module.evalauate(42)
#+end_src
Dave
  • 311
  • 3
  • 10

2 Answers2

14

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.

ph0t0nix
  • 1,119
  • 13
  • 28
  • 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 04 '17 at 10:59
3

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
#+end_src