是否有可能使用knitr生成子图(带有相关的子标题)?这是一个最小的工作示例:
\documentclass{article}
\begin{document}
<<echo = FALSE, fig.cap = c("Some numbers.", "Some more numbers."), out.width = "0.5\\textwidth", fig.align = "center">>=
plot(1:10)
plot(30:100)
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
这导致标记为图1和图2的两个图,其中标题(分别)被定义.但是我希望它们被标记为"图1a"和"图1b",就像使用子标题LaTeX包一样.
我知道有一个knitr选项"fig.env",但这并没有解决它(至少没有使用,例如,"fig.env ='subfigure'").这里有关于Sweave的类似帖子,但解决方案是一个不优雅的黑客:http://texblog.org/2011/12/01/sweave-subfig-controlling-figure-size-and-placement/
我正在使用pgf/tikz图形,我想知道在minipage/subfig环境中使用它们时如何控制图形中字体大小的缩放?
有没有办法手动设置pgf/tikz图形或乳胶中的永久字体大小,以便使字体大小不变为缩放?
理想情况下,我希望能够为每个图形或所有图形或子图形/小型化环境手动指定字体大小?
以下是建议使用的示例.谢谢您的帮助.
\begin{figure}[h]
\centering
\subfloat[Graph 1]{
\begin{minipage}[h]{0.7\linewidth}
\centering\beginpgfgraphicnamed{graph1}
\input{graph1.tex}
\endpgfgraphicnamed
\label{fig:graph1}
\end{minipage}}
\hspace{5pt}
\subfloat[Graph 2]{
\begin{minipage}[h]{0.5\linewidth}
\centering\beginpgfgraphicnamed{graph2}
\input{graph2.tex}
\endpgfgraphicnamed
\label{fig:graph2}
\end{minipage}}
\subfloat[Graph 3]{
\begin{minipage}[h]{0.5\linewidth}
\centering\beginpgfgraphicnamed{graph3}
\input{graph3.tex}
\endpgfgraphicnamed
\label{fig:graph3}
\end{minipage}}
\caption{Three Graphs}
\end{figure}
Run Code Online (Sandbox Code Playgroud)
也许在minipage/subfig之外我可以使用其他帖子的建议来使字体变大,因为图形是用页面宽度缩放的?在这个例子中我想要的是它自己的第一个图像,更大,然后是两个小图像,并排在一个图中,并排在一起.
我在你的个人资料Mica中看到了一些R标签.图形是使用tikzDevice生成的,并在我的latex文档中提取.
所以我在没有tikzpicture环境的情况下生成文件,以便我可以自己手动设置选项.当我使用时,\begin{tikzpicture} \end{tikzpicture}
我得到错误"尺寸太大我不能使用大于19英尺的尺寸.继续,我将使用我能够的最大值." .我需要用\beginpgfgraphicnamed{} .. \endpgfgraphicnamed{}
它才能让它工作?不确定影响究竟是什么.
以下是自动生成文件的示例:
\begin{scope}
\path[clip] ( 0.00, 0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] ( 0.00, 0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
Run Code Online (Sandbox Code Playgroud)
........
\begin{scope}
\path[clip] ( 0.00, 0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{fillColor}{rgb}{1.00,1.00,1.00}
\draw[fill=fillColor,draw opacity=0.00,] …
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的图:
<<foo, fig.lp='', fig.cap='name', fig.subcap=c('left', 'right'),>>=
plot1
plot2
@
Run Code Online (Sandbox Code Playgroud)
现在我想在下面显示一组关于这个图的注释(即多行文本)。在 knitr 创建的图形环境中,有没有什么方便的方法可以做到这一点?
正如上面的评论中已经指出的那样,目前没有解决我的问题的方法。我已提交功能请求。
我试图在 Latex 文档中使用 knitr 将两个子图垂直堆叠而不是并排放置。在 Latex 中,我通常通过在需要彼此堆叠的两个子浮点之间放置一个 '\par' 命令来做到这一点,但我不知道如何将该命令传递给 knitr。
我只能找到一个关于此的主题,使用 knitr 的子图或子标题?. Yihui 给出的例子将数字并排。该线程中的最终答案实现了我的目标,但是使用了相当多的黑客技术,所以我想知道是否有一种简单的方法可以将此命令直接传递给 knitr?
MWE:
\documentclass[a4paper]{article}
\usepackage[font=footnotesize]{subfig}
\begin{document}
<<GeneratePlot>>=
library(ggplot2)
library(tikzDevice)
P1 <- ggplot(data=mpg, aes(x=displ, y=hwy, colour=factor(cyl)))+
geom_line()
P2 <- ggplot(data=mpg, aes(x=displ, y=hwy, colour=factor(cyl)))+
geom_point()
@
<<fig1,eval=TRUE,echo=FALSE,dev='tikz', fig.width=6, fig.height=3, out.width='1\\textwidth', fig.cap='Two figures', fig.subcap=c('Top','Bottom'), fig.show='asis', fig.pos='!htpb', fig.align='center', dependson='GeneratePlot'>>=
P1
P2
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
我还尝试在与输出相同的块中创建绘图对象,但这会产生相同的结果,并且在我的原始文档中,绘图对象是作为更大块的一部分生成的,因此它将具有与 MWE 相同的结构.
我正在使用命令 \begin{subfigure}...\end{subfigure} 并排插入三张图片。但我想知道如何在两者之间留出空间,因为它们彼此太近了。
\begin{figure}
\begin{subfigure}
here's the first image
\end{subfigure}
\begin{subfigure}
here's the second image
\end{subfigure}
\begin{subfigure}
here's the third image
\end{subfigure}
\end{figure}
Run Code Online (Sandbox Code Playgroud) 在我的 rmarkdown 文档中,我想并排包含绘图以节省空间。例如,我想包括:
plot(rnorm(100))
hist(runif(100))
Run Code Online (Sandbox Code Playgroud)
或者
plot(rnorm(100))
hist(runif(100))
Run Code Online (Sandbox Code Playgroud)
我真的不在乎两个子图是否有一个标题或每个子图都有一个标题。我只是想并排包含图形并有一些方法来引用它们(图 1 等)。有人有建议吗?我的标题中有这个:
标头包含: - \usepackage{subfig}
当我的块中没有“fig.show='hold'”时,我的所有标题都工作正常,但我的图不会并排显示。当我添加 Fig.show='hold' 时,布局看起来很棒,但标题消失了。