代码之家  ›  专栏  ›  技术社区  ›  Marco De Virgilis

R标记编译错误

  •  0
  • Marco De Virgilis  · 技术社区  · 8 年前

    我试图写一个乳胶文件的帮助下,包R标记。 我一直在使用TaxMaker等软件,但考虑到我将使用R生成几个图,我想尝试R标记包。

    到目前为止,我有一个非常简单的代码,只是试图理解它的工作原理。这是文件

    ---
    title: "Untitled"
    output: pdf_document
    ---
    \documentclass{article}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage{hyperref}
    \usepackage[latin1]{inputenc}
    
    \title{My Title}
    \author{Me}
    \date{}
    
    \begin{document}
    \maketitle
    
    \end{document}
    

    但是,这不会编译:

    ! LaTeX Error: Can be used only in preamble.
    
    Error: Failed to compile 1.tex. See 1.log for more info.
    Execution halted
    

    相同的代码在标准的乳胶环境中工作得很好。

    我错过了什么? 谢谢

    2 回复  |  直到 8 年前
        1
  •  0
  •   Ralf Stubner    8 年前

    使用rmarkdown时,不必编写乳胶代码。相反,你可以这样写下标记:

    ---
    title: "My title"
    author: "Me"
    date: May 2018
    output: pdf_document
    ---
    
    # Introduction
    
    Some text.
    

    R Markdown: The Definitive Guide 会告诉你所有的细节。

        2
  •  0
  •   jay.sf    8 年前

    在Rmarkdown中,自定义乳胶包的位置是YAML头中的一个列表 header-includes: ,正如论点一样 documentclass: . 最重要的软件包已经包含在内,所以您很少需要显式地配置它们。尤其是在你的例子中, \usepackage[latin1]{inputenc} 似乎不起作用,使用 \usepackage[utf8]{inputenc} 相反。

    ---
    title: "My Title"
    author: me
    output: pdf_document
    documentclass: article
    header-includes:
    - \usepackage{amsmath}
    - \usepackage{graphicx}
    - \usepackage{hyperref}
    - \usepackage[utf8]{inputenc}
    ---
    
    # Header
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    

    enter image description here

    注: 大量乳胶选项可在 Pandoc Manual .