2017-07-03 73 views
0

我想要一个脚本编织一个Rmd文件到PDF文档并面临一些错误。Rmarkdown针织YAML LaTeX错误

我必须说,文档针织很好,如果我点击在Rstudio针织按钮,但它未能编织如果我用命令:

rmarkdown::render('diagnostic.Rmd',output_format = "pdf_document", 
        output_file = "diag.pdf") 

的第一个错误,我得到来自我的这部分代码:

--- 
author: Zigo_datateam 
date: "`r format(Sys.time(), '%d %B, %Y')`" 
geometry: margin=1.6in 
header-includes: "\\usepackage{fancyhdr} \\fancyfoot[CO,CE]{My footer}" 
output: 
    pdf_document: 
    toc: false 
title: "Graphic Layout(Report)" 

--- 

是:

Error in yaml::yaml.load(string, ...) : 
    Scanner error: while scanning a simple key at line 4, column 1could 
    not find expected ':' at line 5, column 1 

所以,如果我删除孔header-includesË上的表达似乎开始编织,但后来我得到这个部分的第二错误(其中来自第二“---”后):

\addtolength{\headheight}{1.0cm} 
\pagestyle{fancyplain} 
\rhead{\includegraphics[height=1.2cm]{logo.png}} 
\renewcommand{\headrulewidth}{0pt} 

错误:

! Undefined control sequence. 
<argument> \undefinedpagestyle 

l.130 ...headheight}{1.0cm} \pagestyle{fancyplain} 

我怎样才能摆脱第一个错误没有得到第二个?

更新:我决定把所有的页脚/标题样式移动到一个单独的文件,我的代码如下所示:

--- 
author: Zigo_datateam 
date: "`r format(Sys.time(), '%d %B, %Y')`" 
geometry: margin=1.6in 
output: 
    pdf_document: 
    includes: 
     in_header: mystyles.sty 
title: "Graphic Layout(Report)" 
--- 

我前面谈到的采空出,但我仍然得到这个的错误:

pandoc: Error producing PDF 
Error: pandoc document conversion failed with error 43 
+0

我会包括乳胶包使用从这里回答:https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown – user20650

+0

你还有'缩进'toc:false'行之后yaml :: yaml.load()中出错? – Anthon

+0

是的,错误仍然存​​在 –

回答

1

在你YAML,使用

header-includes: 
    - \usepackage{fancyhdr} 
    - \fancyfoot[CO,CE]{My footer} 

它应该工作。

+0

这在单击Rstudio中的编织按钮时起作用,但在使用'rmarkdown :: render()时产生相同的错误' –

+0

这很奇怪。我每天都用'render'来使用这种格式。你可以试着将'fancyfoot'移动到文档的正文吗? – Benjamin

+0

是的,我将所有格式都移至单独的“mystyles.sty”文件中,正如我在更新中解释的那样。问题是通过创建一个新的Rmd文件复制/粘贴每一行来解决的。非常感谢你。 –