• R语言
  • 新版Rstudio使用r markdown转为pdf报错,可以成功转为docx和html

C:/Users/ADMINI~1/AppData/Local/Pandoc/pandoc 3.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output 3.pdf --template D:\R-3.1.0\1\library\rmarkdown\rmd\latex\default.tex --highlight-style tango --latex-engine pdflatex --variable geometry:margin=1in

output file: 3.knit.md

! Package inputenc Error: Unicode char \u8:第 not set up for use with LaTeX.

See the inputenc package documentation for explanation.

Type H <return> for immediate help.

...

l.98 \section{第二章R语言作业}

Try running pandoc with --latex-engine=xelatex.

pandoc.exe: Error producing PDF from TeX source

Error: pandoc document conversion failed with error 43

In addition: There were 25 warnings (use warnings() to see them)

Execution halted[s:12][s:12][s:12][s:12][s:12]

是不支持中文吗?去掉中文,包括#注释掉的,便立马可以成功

回复 第2楼 的 fengcheziyou:

bingo,尝试用tex系列生成pdf吧,这样还可以对语言进行控制。

Try running pandoc with --latex-engine=xelatex.

pdflatex好像没什么好的支持中文方案?

1 个月 后

回复 第1楼 的 fengcheziyou:我也有类似的问题,楼主,你现在有什么好的解决方法吗?

刚收到邮件通知,现在可以用showtext包来解决PDF正文与图片输出的中文问题了,设置

fig.showtext=TRUE
调用showtext包即可,详参 https://github.com/yihui/knitr/issues/799 中的示例
</p>
3 个月 后

我也遇到同样的问题了,不知道怎么解决,以前用中文是正常的!

根据帖子修改了,能正常生成PDF,但是所有中文都是“......”这样的点点点,请教大大们,还需要哪里设置或者配置下?或者是编码问题吗?

我的也是这样的, http://cos.name/cn/topic/158579

7 个月 后
到2015年6月,Rstudio更新了很多,写R代码和写chunk中的条件控制参数时有了逐渐提示功能,这一点很好。另外,使用markdown来中英文混合输入,也能解决了。我用以下方法解决的:
1)找到default.tex文件,我的电脑是在这里:F:\Users\chenwf\Documents\R\win-library\3.1\rmarkdown\rmd\latex,你自己的可通过查找方式找到此文件,注意一定是rmd\latex文件夹下的,不是beamer文件下的。
2)打开default.tex,在\begin{document}之前,加上:
\usepackage[UTF8,nofonts]{ctex}
然后保存关闭。
3)在Rstudio中,编码用UTF-8。
4)在Rstudio中,Knit PDF右侧的设置中,Advanced,使用pdflatex编译。
各项设置好后,就可以使用中文了。

目前还解决不了在chunk中使用中文的问题。虽然上面提到showtext包,但我的还不行。

但我已很满足了,毕竟,图中基本不需要中文,在图的外面写中文才是我真正需要的。
2 个月 后
[未知用户]
大哥,并不好使啊。。。
然而并不是很好用……是新版本的问题么……
前天同样的代码还行得通,昨天开始 knitr 和 rmarkdown 就出现错误信息。
> render(paste0(getwd(),'/SO datasets/Betting_Strategy_and_Model_Validation.Rmd'),'all')
Error in yaml::yaml.load(enc2utf8(string), ...) : 
  Parser error: while parsing a block mapping at line 1, column 1did not find expected key at line 2, column 41
> browseURL(paste0(getwd(),'/Betting_Strategy_and_Model_Validation.html'))
res <- llply(split(smp, smp$Test1), function(x) head(kable(x[order(x$Date, decreasing = TRUE), 
    ])))

我从上面的rmarkdown代码换成下面的代码,结果还是一样的结果杂乱无章。 :plain:
res <- llply(split(smp, smp$Test1), function(x) x[order(x$Date, decreasing = TRUE), 
    ])
head(kable(res$alcohol))
head(kable(res$tabacco))

[1] " No Code Container Price S.median S.Mean S.sd Count PL PL.percent" [2] “— —— —– ——— ———– ——— ———- ———– —— ———- ———–” [3] “17 12.9 110 Alcohol 2339962500 330000 459717.6 501185.27 5090 18457062 0.0078878” [4] “15 23.7 112 Alcohol 1794915000 370000 532615.7 740154.36 3370 77640375 0.0432557” [5] “14 12.5 007 Tabacco 1574068400 300000 443774.6 571082.57 3547 522896525 0.3321943” [6] “18 14.50 012 Tabacco 1345432000 250000 383860.8 500513.35 3505 -4051590 -0.0030114”
解决了,将领袖head换成row...(叹气)
llply(split(smp, smp$Test1), function(x) kable(x[order(x$Date, decreasing = TRUE),][1:6,]))