获取Sweave代码块以保留在页边距内? [英] Getting Sweave code chunks to stay inside page margins?
问题描述
有时候,我需要制作一个R代码块(在Sweave中),该代码块的长度比页面的页边空白长.一旦发生这种情况,是否有办法强制其转到下一行"?
Sometimes I get to make an R code chunk (in Sweave) which is longer then the margins of the page. Is there a way to force it to "go to the next line" once that happens?
这是一个简单的例子:
\documentclass[a4paper]{article}
\usepackage{Sweave}
\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em,
frame=single}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em,
frame=single}
\title{Sweave with boxes}
\begin{document}
\maketitle
<<echo=FALSE>>=
options(width=60)
@
Here is an example of a code chunk followed by an output chunk,
both enclosed in boxes.
<<>>=
print(rnorm(99))
@
<<>>=
print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
@
\end{document}
推荐答案
这是一个困难而极端的情况,因为这些a
之间没有空格,因此LaTeX可能无法包装这些单词.如果确实有空格,则knitr
将能够用长行将其包裹在tidy=TRUE, highlight=TRUE
中来产生输出(如果您设置了keep.source=FALSE
,我想也将是Sweave).
This is a difficult and extreme case, because you do not have spaces among those a
's, so LaTeX may not be able to wrap the words. If you do have spaces, knitr
will be able to produce the output with the long lines wrapped with tidy=TRUE, highlight=TRUE
(so will Sweave, I think, if you set keep.source=FALSE
).
这篇关于获取Sweave代码块以保留在页边距内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!