代码之家  ›  专栏  ›  技术社区  ›  user1591727

R bookdown-自定义标题页

  •  6
  • user1591727  · 技术社区  · 7 年前

    如何使用bookdown自定义标题页?

    我尝试在YAML标头中使用以下代码。

    includes:
      in_header: preamble.tex
      before_body: body.tex
    

    身体。tex文件非常简单,只是为了测试:

    \begin{titlepage}
    Hello world
    \end{titlepage}
    
    2 回复  |  直到 7 年前
        1
  •  11
  •   Ralf Stubner    7 年前

    在LaTeX模板中 <R-Library>/rmarkdown/rmd/latex/default-1.17.0.2.tex 我们看到了

    \begin{document}
    $if(title)$
    \maketitle
    $endif$
    $if(abstract)$
    \begin{abstract}
    $abstract$
    \end{abstract}
    $endif$
    
    $for(include-before)$
    $include-before$
    

    这意味着标题页是使用 \maketitle 如果a title 在YAML标头中定义。类似于 abstract . 如果从YAML标题中删除这两个标记,则文件中的内容 body.tex 将是第一个被处理的,您可以在那里自由定制您的标题页。

    查看的答案 this question 寻找替代方法。

        2
  •  1
  •   user1591727    7 年前

    我最终编辑了 _output.yml 要引用副本的文件 default-1.17.0.2.tex 使用yaml模板标记在我的R项目目录中创建模板。

    bookdown::gitbook:
      css: style.css
      config:
        toc:
          before: |
            <li><a href="./">A Minimal Book Example</a></li>
          after: |
            <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
        edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
        download: ["pdf", "epub"]
    bookdown::pdf_book:
        fig_caption: true
        number_sections: yes
        includes:
            in_header: preamble.tex
        latex_engine: xelatex
        citation_package: natbib
        keep_tex: yes
        template: template.tex
    bookdown::epub_book: default
    

    由于某种原因,我在编译pdf时出错(!Undefined control sequence…)所以我加入了一个latex命令 \usepackage{graphicx} 在里面 template.tex 来修复它。现在,我可以自由定制标题页和其他内容。