编织块选项可控制行距,输出中的字体大小 [英] knitr chunk options to control line spacing, font size in output

查看:77
本文介绍了编织块选项可控制行距,输出中的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更好地控制用于 代码块和R通过LaTeX输出.使用默认的render_latex(),我可以 设置全局使用(在我的前提下)

I'd like to have more control over the font size and line spacing used for code chunks and R output via LaTeX. Using the default render_latex(), I see I can set both globally using (in my premable)

\renewenvironment{knitrout}{\small\renewcommand{\baselinestretch}{.85}}{} 
...
\begin{document}

但是,说有一些块我想用\ footnotesize打印,或者用其他一些自定义 道路.我知道我可以使用LaTeX小组执行此操作,但不能使用knitrout环境执行此操作:

But, say there are chunks I'd like to print in \footnotesize, or customize in some other way. I know I can do this with a LaTeX group, but not with the knitrout environment:

{\small
\renewcommand{\baselinestretch}{.85}
<<arth-csv, eval=FALSE, results='asis'>>=
ID,Treatment,Sex,Age,Improved
57,Treated,Male,27,Some
46,Treated,Male,29,None
...
71,Placebo,Female,68,Some
1,Placebo,Female,74,Marked
@
}

使用render_listings()和Listings包这样做会更容易吗?

Would it be easier to do this using render_listings() and the listings package?

我可以使用自定义的块选项和块挂钩来实现更好的控制吗?

Can I use custom chunk options and chunk hooks to achieve better control?

推荐答案

为部分回答我自己的问题,我发现了knitr size=块选项,该选项在AFAIK中有效,仅适用于 render_latex()和突出显示包.因此,要在脚注大小中设置较大的输出,我可以使用

To partially answer my own question, I discovered the knitr size= chunk option, which works, AFAIK, only with render_latex() and the highlight package. Thus, for a wide output to be set in footnote size, I can use

<<tv3, size="footnotesize">>=
TV <- TV[,,1:3,]     # keep only ABC, CBS, NBC
TV <- TV[,,,3]       # keep only Persist -- now a 3 way table
structable(TV)
@

此外,我上面在results='asis'中使用的示例应该仅在verbatim LaTeX环境中完成, 不像代码块那样.即使我使用过eval=FALSE,knitr也会尝试解析文本并生成警告.

Also, the example I used above with results='asis' should have been done just with a verbatim LaTeX environment, not as as code chunk. Even though I had used eval=FALSE, knitr tries to parse the text and generates a warning.

{\footnotesize
\renewcommand{\baselinestretch}{.85}
\begin{verbatim}
ID,Treatment,Sex,Age,Improved
57,Treated,Male,27,Some
46,Treated,Male,29,None
...
71,Placebo,Female,68,Some
1,Placebo,Female,74,Marked
\end{verbatim}
}

这篇关于编织块选项可控制行距,输出中的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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