Beamer中带有编织器和乳胶的代码块字体大小 [英] Code chunk font size in Beamer with knitr and latex

查看:98
本文介绍了Beamer中带有编织器和乳胶的代码块字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一些R代码以适合我的投影仪幻灯片.似乎无法像其他编织类型文档那样通过代码块的size参数更改字体大小.唯一的方法似乎是在每个代码块之前使用\footnotesize.令人沮丧的是,我有很多代码块,在许多情况下,之后我必须在LaTeX项目符号要点之后使用\normalsize.

I am trying get some R code to fit on my beamer slides. It does not seem possible to change the font size via the size argument for the code chunk as you might do for other knitr type documents. The only way seems to be with \footnotesize before every code chunk. This is gets frustrating, as I have lots of code chunks and in many cases I then have to use \normalsize after for my LaTeX bullet points.

---
title: "Untitled"
output:
 beamer_presentation:
  includes:
   in_header: header.txt
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, size = "footnotesize")
```

## R Markdown

```{r}
summary(cars)
```

\footnotesize
```{r}
summary(cars)
```

在下面的header.txt中,我尝试了 http://://yihui.name/knitr/demo/beamer/但没有运气.

In my header.txt (below) I have experimented with a couple of bits of code from http://yihui.name/knitr/demo/beamer/ but with no luck.

\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi

\makeatletter
\let\oldalltt\alltt
\def\alltt{\@ifnextchar[\alltt@i \alltt@ii}
\def\alltt@i[#1]{\oldalltt[#1]\footnotesize}
\def\alltt@ii{\oldalltt\footnotesize}
\makeatother

...但是我真的很喜欢\def.

... but really out my depth with \def.

推荐答案

借鉴此tex.SE答案 ,我们可以重新定义包围R代码的Shaded环境以使其具有脚注大小(以及用于输出的verbatim环境).将此添加到您的header.txt:

Drawing on this tex.SE answer, we could redefine the Shaded environment that surrounds R code to make it footnotesize (and the verbatim environment for output). Add this to your header.txt:

%% change fontsize of R code
\let\oldShaded\Shaded
\let\endoldShaded\endShaded
\renewenvironment{Shaded}{\footnotesize\oldShaded}{\endoldShaded}

%% change fontsize of output
\let\oldverbatim\verbatim
\let\endoldverbatim\endverbatim
\renewenvironment{verbatim}{\footnotesize\oldverbatim}{\endoldverbatim}

这篇关于Beamer中带有编织器和乳胶的代码块字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆