简体   繁体   English

knitr没有将数字与pdf输出中心对齐 - 替代方案?

[英]knitr not aligning figures to center in pdf output--alternatives?

Using knitr to make pdfs, the figures don't show when using the fig.align='center' option: 使用knitr制作pdf时,使用fig.align='center'选项时,数字不显示:

require(knitr)
opts_chunk$set(fig.align='center') 

OR 要么

```{r chunkname, fig.align='center'}
...code that makes figure...
```

Either way, no figures come out on the pdf when pressing the knit PDF button. 无论哪种方式,在按下编织PDF按钮时,pdf上都没有数字。 But I remove the fig.align option and the figures appear, left aligned. 但我删除了fig.align选项,数字显示,左对齐。

Tried it with fig_crop: false in the YAML header, too, same results. 在YAML标题中用fig_crop: false尝试了它,结果相同。

This hints at why it's not working: https://github.com/rstudio/rmarkdown/issues/86 but it doesn't cover what to do instead if we need figures centered. 这暗示了为什么它不起作用: https//github.com/rstudio/rmarkdown/issues/86但是如果我们需要以数字为中心,它不会涵盖要做什么。 I could just produce the plot as a png and import it with rmarkdown, but that is definitely not in the spirit of reproducible research! 我可以将这个情节作为png生成并用rmarkdown导入它,但这绝对不是可重复研究的精神!

Any ideas what to do? 有什么想法怎么办?

## R version 3.1.1 (2014-07-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## RStudio Version 0.98.1028

(This is not a duplicate of Knitr: opts_chunk$set() not working in Rscript command ) (这不是 Knitr的副本:opts_chunk $ set()在Rscript命令中不起作用

This has been fixed in the development version of knitr , which I plan to release to CRAN in the next few days, and the version will be 1.8 if everything goes well with CRAN maintainers. 这已在knitr开发版本中得到修复 ,我打算在接下来的几天内发布到CRAN,如果CRAN维护者的一切顺利,版本将为1.8。

The reason for the original failure to align figures is that when fig.align is specified, the HTML syntax for images will be used (ie <img src=... style=... /> ), and Pandoc is unable to convert this to LaTeX properly. 原始无法对齐数字的原因是,当指定fig.align时,将使用图像的HTML语法(即<img src=... style=... /> ),并且Pandoc无法转换这对LaTeX来说很合适。 knitr 1.8 will just use raw LaTeX syntax to write figures, which will be preserved during the conversion from Markdown to LaTeX due to its raw_tex extension. knitr 1.8将只使用原始LaTeX语法来编写数字,由于其raw_tex扩展名,它将在从Markdown到LaTeX的转换过程中保留。

As a workaround (see comment by Yihui ) you could keep the .tex file and manually center the image: 作为一种解决方法(请参见Yihui的评论),您可以保留.tex文件并手动居中图像:

\centering
\includegraphics[]{…}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM