r - 避免代码块破坏 Knitr? (最好使用 block 选项)

标签 r pdf break knitr floating

使用 knitr 创建 pdf,codechunks 根据分页符进行分页。通常这正是我想要的,但在某些情况下,我希望能够避免这种情况。例如。如果它不适合当前页面,则通过使代码块跳转到下一页。我希望这可以在一个 block 选项中完成,即不使用例如。\newpage 等

以下是中断的代码块的示例。我该如何避免这种情况?

\documentclass{article}
\usepackage[english]{babel}
\usepackage{lipsum}

\begin{document}

\lipsum[1-3] \textbf{The following chunk will break. How do I avoid this breaking? }



<<echo=TRUE>>=

(iris)[1:20,]

@



\end{document}

最佳答案

我离开了一个空的环境knitroutknitr为此类目的而设计。你可以重新定义这个环境来实现你想要的。有许多不可破坏的 LaTeX 环境,例如 figure环境。下面我使用 minipage以环境为例:

\documentclass{article}
\renewenvironment{knitrout}{\begin{minipage}{\columnwidth}}{\end{minipage}}
% alternatively, you can use `figure`
% \renewenvironment{knitrout}{\begin{figure}}{\end{figure}}
\begin{document}

\begin{figure}
\caption{One figure.}
\end{figure}

% placeholder
\framebox{\begin{minipage}[t][0.3\paperheight]{1\columnwidth}%
nothing
\end{minipage}}

<<echo=TRUE>>=
(iris)[1:20,]
@

\begin{figure}
\caption{Another one.}
\end{figure}

\end{document}

关于r - 避免代码块破坏 Knitr? (最好使用 block 选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655332/

相关文章:

r - R data.table 的合并指示器?

r - freq() 在打印期间重命名列

r - 通过匹配变量将值从一个 data.frame 添加到另一个 data.frame

r - 如何在 R 中用中间结果改变新列,累积或减少

php - 如何在 PHP 中生成多语言内容 Pdf

perl - 以编程方式更改 PDF 中所有线条的宽度

pdf - 从 Plone 内容类型生成 PDF

lua - 在没有 ctrl -c 退出的情况下中断 lua 解释

python - while 循环不会中断,当计数器不再小于数组长度时应该中断

python-3.x - python : Unable to call function when in while loop