Set custom font size for code chunks in HTML5 slides?

1,120 views
Skip to first unread message

Eric

unread,
May 8, 2012, 5:13:13 PM5/8/12
to kn...@googlegroups.com
Hello,

First I wanted to say thank you for creating such a powerful package for reproducible research!  I've been able to create excellent presentations in LaTeX - beamer using knitr and now I'd like to try using the markdown / HTML5 slides workflow from Yihui's great tutorial here .  It was unclear to me if there is a way to control the font size used in the R code / output chunks, as there will be cases where I would like to put more lines of code but use a smaller font.  For example, I'd like to make the font size of the R code smaller showing code and a ggplot2 visualization in a slide like http://yihui.name/slides/knitr-slides.html#4.0 .  For my previous presentations using LaTeX and beamer, I included the code snippet here to make all of the font sizes smaller:

% use footnotesize for knitr output
\ifdefined\knitrout
  \renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi

Is there an option I can use either in specific chunks or globally in R markdown files (.Rmd) to control the font size?  From the knitr documentation it appeared that the size option only applied to LaTeX documents. 

Regards,
Eric

www.r-podcast.org

Carl Boettiger

unread,
May 8, 2012, 5:38:10 PM5/8/12
to Eric, kn...@googlegroups.com
Hi Eric,

If I understand your question correctly, I think this would probably best be done by customizing the CSS at the top of the template html file that pandoc uses to generate the html5 slides, rather than in knitr.  Look at default.dzslides in your pandoc installation, you'll see the default font size is 20pt:

```
  /* A section is a slide. It's size is 800x600, and this will never change */
  section {
      font-family: Arial, serif;
      font-size: 20pt;
    }
```

Might be more tricky to customize slide-by-slide.  Pandoc users might have some hints?


-Carl
--
Carl Boettiger
UC Davis
http://www.carlboettiger.info/

Yihui Xie

unread,
May 8, 2012, 6:03:54 PM5/8/12
to Carl Boettiger, Eric, kn...@googlegroups.com
Thanks, Carl. That is correct. CSS customization is the way to go.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
Reply all
Reply to author
Forward
0 new messages