图*twocolumn knit/Sweave 文档中的环境
听起来这应该是一个常见问题,但我没有找到明显的技巧。 考虑下面的 knit Rnw 文件,
\documentclass[twocolumn, 12pt]{article}
\usepackage{graphicx}
\begin{document}
%\SweaveOpts{dev=pdf, fig.align=center}
\begin{figure*}
<<aaa, fig.width=8, fig.height=5, fig.show=hold>>=
plot(1,1)
@
\end{figure*}
\end{document}
我希望这个宽图跨越两列,使用 {figure*}
LaTeX 环境。有一个钩子吗?
编辑:将块包装在 figure*
中给出以下输出。
Sounds like it should be a common problem, but I didn't find an obvious trick.
Consider the knitr Rnw file below,
\documentclass[twocolumn, 12pt]{article}
\usepackage{graphicx}
\begin{document}
%\SweaveOpts{dev=pdf, fig.align=center}
\begin{figure*}
<<aaa, fig.width=8, fig.height=5, fig.show=hold>>=
plot(1,1)
@
\end{figure*}
\end{document}
I would like this wide figure to span two columns, using a {figure*}
LaTeX environment. Is there a hook for that?
EDIT: wrapping the chunk in figure*
gives the following output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
两个事实:
knitr
让您可以轻松访问所有内容,因此 LaTeX 技巧通常是不必要的;chunk
钩子,您可以用它包装块结果;一个简单的解决方案是:
我将剩下的工作留给您来处理
options
中的更多细节(例如,当options$fig.keep == 'none'
,您不应将输出包装在figure*
中)。您可能想了解默认的chunk
钩子 for LaTeX 在knitr
中定义,以便更好地了解chunk
钩子的工作原理。然而,在这种情况下,我倾向于自己在文档中编写LaTeX代码,而不是自动创建它。获得
figure*
后,您可能会开始考虑\caption{}
和\label{}
(不难,但我仍然想在 LaTeX 中看到它们)。Two facts:
knitr
makes everything accessible for you, so LaTeX tricks are often unnecessary;chunk
hook with which you can wrap your chunk results;A simple-minded solutions is:
I leave the rest of work to you to take care of more details in
options
(e.g. whenoptions$fig.keep == 'none'
, you should not wrap the output infigure*
). You may want to see how the defaultchunk
hook for LaTeX is defined inknitr
to know better how thechunk
hook works.However, in this case, I tend to write the LaTeX code by myself in the document instead of automatically creating it. After you have got
figure*
, you may start to think about\caption{}
and\label{}
(not hard, but I still want to see them in LaTeX).不确定如何knitr,但对于Sweave(和基本乳胶)来说,实际上有一个技巧:让R代码生成一个pdf文件,然后使用标准的
\includegraphics
将其拉入。所以用这个:
我得到了下面的文档(然后我将其从 pdf 转换为 png):
Not sure about how knitr but for Sweave (and basic latex) there is in fact a trick: have the R code produce a pdf file, and then use standard
\includegraphics
to pull it in.So with this:
I got the document below (which I then converted from pdf to png):
在准备 IEEE 两栏会议论文中应跨越两栏的图表时,我也遇到了类似的问题。
设置块钩子导致我的设置出现一些奇怪的错误。
即使是这个简单的钩子:
knit_hooks$set(chunk = function(x, options) x)
但在研究
knitr::opts_chunk$get()
之后,我意识到这很简单设置fig.env="figure*"
以优雅的方式解决了这个问题。这是我的块在 Rnw 文件中的样子:
I also had a similar problem while preparing a figure that should span two columns in a IEEE two-column conference paper.
Setting the chunk hook caused some strange error in my setup.
Even this simple hook:
knit_hooks$set(chunk = function(x, options) x)
But after looking into
knitr::opts_chunk$get()
, I realized that simply settingfig.env="figure*"
solves the problem in an elegant way.Here is how my chunk looks like in an Rnw file: