gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:32:22 26 4
gpt4 key购买 nike

使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com