小编JAl*_*len的帖子

一个块内的编织图,标签和标题

我正在制作一份乳胶报告,在dlply电话中产生多个图.dlply调用当然只有一个块,为了让标签和标题发生变化我正在使用Steve Powell的片段.该方法有效,但似乎knitr没有正确格式化输出.一个简单的例子演示:

\documentclass{article}

\begin{document}
<startup,echo=FALSE,results='hide',message=FALSE,tidy=FALSE,warning=FALSE,fig.keep='all',comment=NA>>=
require(knitr)
require(ggplot2)
opts_knit$set(progress = F, verbose = F)
opts_chunk$set(comment=NA,
           tidy=FALSE,
           warning=FALSE, 
           message=FALSE, 
           echo=FALSE, 
           dpi=600,
           fig.width=6.75, fig.height=4, # Default figure widths
           dev=c("pdf",'tiff'),
           dev.args=list(pdf=list(NULL),tiff=list(compression='lzw')),
           error=FALSE)
@
<<plotloop,results='asis'>>=
for(x in seq(1,20)){
  x1<-data.frame(x=seq(1,10),y=seq(1,10))
  plt<-ggplot(data=x1,aes(x,y))+geom_point()
  figLabel=paste('Figure',x,sep='')
  capt<-paste('Caption for fig.',x)
  cat(knit(text=(paste("<<",figLabel,",fig.pos='ht',fig.cap='",capt,"'>>=\nplt\n@",sep=''))))
}
@
\end{document}
Run Code Online (Sandbox Code Playgroud)

这几乎可行.问题是knitr将关闭\标题括号放在\ label大括号外面,可以在下面的.tex文件的片段中看到:

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}
\color{fgcolor}
\begin{figure}[ht]
\includegraphics[width=\maxwidth]{figure/Figure1} \caption[Caption for fig]{Caption for fig. 1\label{fig:Figure1}}
\end{figure}
\end{knitrout}
Run Code Online (Sandbox Code Playgroud)

乳胶可以处理这个,如果只有这样的几个数字,但有大量的情节,它开始错误地放置它们.我也试过这个

fig.cap=paste('testLoop',seq(1,20))
Run Code Online (Sandbox Code Playgroud)

接近并获得相同的结果.

进一步说明:我在维基百科的Latex/Floats页面上找到了这个:

如果你想标记一个数字以便以后可以引用它,你必须在标题之后添加标签(内部似乎在LaTeX 2e中工作)但在浮动环境中.如果在外面声明它,它将给出节号.

'内部似乎在LaTeX 2e中工作'部分引起了我的注意.它似乎只是因为错误被忽略了很多次?我正在使用LaTeX2e <2005/12/01>.我认为代码位于hooks-latex.R的hook_plot_tex函数行120中:

fig2 = sprintf('\\caption%s{%s\\label{%s}}\n\\end{%s}\n', scap, cap,
                 paste(lab, if …
Run Code Online (Sandbox Code Playgroud)

r knitr

11
推荐指数
1
解决办法
2712
查看次数

RStudio Pandoc Beamer添加\ frame选项

我希望能够通过RStudio-Rmarkdown-Pandoc-Beamer路径将帧选项传递给投影仪。这将允许利用Beamer的选项来抑制打印帧。Beamer允许以下操作:

\documentclass[handout]{beamer}
\begin{document}

\begin{frame}
Slide 1
\end{frame}

\begin{frame}<handout:0>
Slide 2 to be suppressed
\end{frame}

\end{document}
Run Code Online (Sandbox Code Playgroud)

我知道可以将pandoc .tex模板更改为静态添加选项以滑动帧,但是想即时执行以下操作:

##Slide 1

## Slide 2 <handout:0>
Run Code Online (Sandbox Code Playgroud)

beamer pandoc rstudio r-markdown

8
推荐指数
1
解决办法
258
查看次数

在docx中将标题添加到flextable

如何将标题添加到呈现给docx的弹性表中?编辑:目的是产生一个适当的标题,可以在文档中引用该标题以产生表和内联引用的列表。

iris.t <-
  iris[1:5,] %>%
  regulartable() %>% 
  style(pr_c = officer::fp_cell(vertical.align = "bottom",
                                border.bottom = officer::fp_border(width = 2)), part = "header") %>% 
  rotate(j = names(iris)[-c(1:2)],
         rotation = "tbrl", part = "header", align = "bottom") %>% 
  height(height = max(dim_pretty(., part = "header")$widths), part = "header") %>% 
  width(width = dim_pretty(.,part = "body")$widths)

iris.t 
Run Code Online (Sandbox Code Playgroud)

r flextable knitr r-markdown

5
推荐指数
1
解决办法
1326
查看次数

标签 统计

knitr ×2

r ×2

r-markdown ×2

beamer ×1

flextable ×1

pandoc ×1

rstudio ×1